﻿#include "NPCSegment.h"
#include "../../Settings.h"
#include "NPCScript.h"
#include "../ConquestObject.h"
#include "../../MirEnvir/Map.h"
#include "../NPCObject.h"
#include "../../../Shared/Data/Stat.h"
#include "../../../Shared/Functions/Functions.h"
#include "../../../Shared/Globals.h"
#include "../../../Shared/Packet.h"
#include "../../MirDatabase/MonsterInfo.h"
#include "../../../Shared/ServerPackets.h"
#include "../../MirDatabase/MailInfo.h"
#include "../../../Shared/Data/ItemData.h"
#include "../../MirDatabase/MagicInfo.h"
#include "../DelayedAction.h"
#include "../GuildObject.h"
#include "../../../Shared/Functions/IniReader.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirObjects
{

    Server::MirEnvir::Envir *NPCSegment::getEnvir()
    {
        return Envir::getMain();
    }

    Server::MessageQueue *NPCSegment::getMessageQueue()
    {
        return MessageQueue::getInstance();
    }

    NPCSegment::NPCSegment(NPCPage *page, std::vector<std::string> &say, std::vector<std::string> &buttons, std::vector<std::string> &elseSay, std::vector<std::string> &elseButtons, std::vector<std::string> &gotoButtons)
    {
        Page = page;

        Say = say;
        Buttons = buttons;

        ElseSay = elseSay;
        ElseButtons = elseButtons;

        GotoButtons = gotoButtons;
    }

    std::vector<std::string> NPCSegment::ParseArguments(std::vector<std::string> &words)
    {
        Regex *r = new Regex(R"(\%ARG\((\d+)\))");

        for (int i = 0; i < words.size(); i++)
        {
            for (auto m : *r->Matches(StringHelper::toUpper(words[i])))
            {
                if (!m->Success)
                {
                    continue;
                }

                int sequence = std::stoi(m->Groups[1]->Value);

                if (Page->Args.size() >= (sequence + 1))
                {
                    words[i] = StringHelper::replace(words[i], m->Groups[0]->Value, Page->Args[sequence]);
                }
            }
        }

        delete r;
        return words;
    }

    void NPCSegment::AddVariable(MapObject *player, const std::string &key, const std::string &value)
    {
        Regex *regex = new Regex(R"([A-Za-z][0-9])");

        if (!regex->Match(key)->Success)
        {
            delete regex;
            return;
        }

        for (int i = 0; i < player->NPCVar.size(); i++)
        {
//C# TO C++ CONVERTER TODO TASK: The following .NET 'String.Equals' reference is not converted:
            if (!std::string::Equals(player->NPCVar[i]->first, key, StringComparison::CurrentCultureIgnoreCase))
            {
                continue;
            }
            player->NPCVar[i] = KeyValuePair<std::string, std::string>(player->NPCVar[i]->first, value);

            delete regex;
            return;
        }

        player->NPCVar.push_back(KeyValuePair<std::string, std::string>(key, value));

        delete regex;
    }

    std::string NPCSegment::FindVariable(MapObject *player, const std::string &key)
    {
        Regex *regex = new Regex(R"(\%[A-Za-z][0-9])");

        if (!regex->Match(key)->Success)
        {
            delete regex;
            return key;
        }

        std::string tempKey = key.substr(1);

        for (auto t : *player->NPCVar)
        {
//C# TO C++ CONVERTER TODO TASK: The following .NET 'String.Equals' reference is not converted:
            if (std::string::Equals(t.first, tempKey, StringComparison::CurrentCultureIgnoreCase))
            {
                delete regex;
                return t.second;
            }
        }

        delete regex;
        return key;
    }

    void NPCSegment::ParseCheck(const std::string &line)
    {
        auto parts = line.Split(std::vector<char> {' '}, StringSplitOptions::RemoveEmptyEntries);

        parts = ParseArguments(parts);

        if (parts.empty())
        {
            return;
        }

        std::string tempString, tempString2;

        auto regexFlag = new Regex(R"(\[(.*?)\])");
        auto regexQuote = new Regex("\"([^\"]*)\"");

        Match *quoteMatch;

//C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic:
//        switch (parts[0].ToUpper())
//ORIGINAL LINE: case "LEVEL":
        if (StringHelper::toUpper(parts[0]) == "LEVEL")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar(CheckType::Level, {parts[1], parts[2]});
                CheckList.push_back(&tempVar);

        }
//ORIGINAL LINE: case "CHECKGOLD":
        else if (StringHelper::toUpper(parts[0]) == "CHECKGOLD")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar2(CheckType::CheckGold, {parts[1], parts[2]});
                CheckList.push_back(&tempVar2);
        }
//ORIGINAL LINE: case "CHECKGUILDGOLD":
        else if (StringHelper::toUpper(parts[0]) == "CHECKGUILDGOLD")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar3(CheckType::CheckGuildGold, {parts[1], parts[2]});
                CheckList.push_back(&tempVar3);
        }
//ORIGINAL LINE: case "CHECKCREDIT":
        else if (StringHelper::toUpper(parts[0]) == "CHECKCREDIT")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar4(CheckType::CheckCredit, {parts[1], parts[2]});
                CheckList.push_back(&tempVar4);
        }
//ORIGINAL LINE: case "CHECKITEM":
        else if (StringHelper::toUpper(parts[0]) == "CHECKITEM")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                tempString = parts.size() < 3 ? "1" : parts[2];
                tempString2 = parts.size() > 3 ? parts[3] : "";

                NPCChecks tempVar5(CheckType::CheckItem, {parts[1], tempString, tempString2});
                CheckList.push_back(&tempVar5);

        }
//ORIGINAL LINE: case "CHECKGENDER":
        else if (StringHelper::toUpper(parts[0]) == "CHECKGENDER")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar6(CheckType::CheckGender, {parts[1]});
                CheckList.push_back(&tempVar6);

        }
//ORIGINAL LINE: case "CHECKCLASS":
        else if (StringHelper::toUpper(parts[0]) == "CHECKCLASS")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar7(CheckType::CheckClass, {parts[1]});
                CheckList.push_back(&tempVar7);

        }
//ORIGINAL LINE: case "DAYOFWEEK":
        else if (StringHelper::toUpper(parts[0]) == "DAYOFWEEK")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }
                NPCChecks tempVar8(CheckType::CheckDay, {parts[1]});
                CheckList.push_back(&tempVar8);

        }
//ORIGINAL LINE: case "HOUR":
        else if (StringHelper::toUpper(parts[0]) == "HOUR")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar9(CheckType::CheckHour, {parts[1]});
                CheckList.push_back(&tempVar9);

        }
//ORIGINAL LINE: case "MIN":
        else if (StringHelper::toUpper(parts[0]) == "MIN")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar10(CheckType::CheckMinute, {parts[1]});
                CheckList.push_back(&tempVar10);

            //cant use stored var
        }
//ORIGINAL LINE: case "CHECKNAMELIST":
        else if (StringHelper::toUpper(parts[0]) == "CHECKNAMELIST")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                std::string listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                auto fileName = FileSystem::combine(Settings::NameListPath, listPath);

                std::string sDirectory = FileSystem::getDirectoryName(fileName);
                FileSystem::createDirectory(sDirectory);

                if (FileSystem::fileExists(fileName))
                {
                    NPCChecks tempVar11(CheckType::CheckNameList, {fileName});
                    CheckList.push_back(&tempVar11);
                }

            //cant use stored var
        }
//ORIGINAL LINE: case "CHECKGUILDNAMELIST":
        else if (StringHelper::toUpper(parts[0]) == "CHECKGUILDNAMELIST")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                fileName = FileSystem::combine(Settings::NameListPath, listPath);

                sDirectory = FileSystem::getDirectoryName(fileName);
                FileSystem::createDirectory(sDirectory);

                if (FileSystem::fileExists(fileName))
                {
                    NPCChecks tempVar12(CheckType::CheckGuildNameList, {fileName});
                    CheckList.push_back(&tempVar12);
                }
        }
//ORIGINAL LINE: case "ISADMIN":
        else if (StringHelper::toUpper(parts[0]) == "ISADMIN")
        {
                NPCChecks tempVar13(CheckType::IsAdmin);
                CheckList.push_back(&tempVar13);

        }
//ORIGINAL LINE: case "CHECKPKPOINT":
        else if (StringHelper::toUpper(parts[0]) == "CHECKPKPOINT")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar14(CheckType::CheckPkPoint, {parts[1], parts[2]});
                CheckList.push_back(&tempVar14);

        }
//ORIGINAL LINE: case "CHECKRANGE":
        else if (StringHelper::toUpper(parts[0]) == "CHECKRANGE")
        {
                if (parts.size() < 4)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar15(CheckType::CheckRange, {parts[1], parts[2], parts[3]});
                CheckList.push_back(&tempVar15);

        }
//ORIGINAL LINE: case "CHECKMAP":
        else if (StringHelper::toUpper(parts[0]) == "CHECKMAP")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar16(CheckType::CheckMap, {parts[1]});
                CheckList.push_back(&tempVar16);

            //cant use stored var
        }
//ORIGINAL LINE: case "CHECK":
        else if (StringHelper::toUpper(parts[0]) == "CHECK")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }
                auto match = regexFlag->Match(parts[1]);
                if (match->Success)
                {
                    std::string flagIndex = match->Groups[1]->Captures[0]->Value;
                    NPCChecks tempVar17(CheckType::Check, {flagIndex, parts[2]});
                    CheckList.push_back(&tempVar17);
                }

        }
//ORIGINAL LINE: case "CHECKHUM":
        else if (StringHelper::toUpper(parts[0]) == "CHECKHUM")
        {
                if (parts.size() < 4)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                tempString = parts.size() < 5 ? "1" : parts[4];
                NPCChecks tempVar18(CheckType::CheckHum, {parts[1], parts[2], parts[3], tempString});
                CheckList.push_back(&tempVar18);

        }
//ORIGINAL LINE: case "CHECKMON":
        else if (StringHelper::toUpper(parts[0]) == "CHECKMON")
        {
                if (parts.size() < 4)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                tempString = parts.size() < 5 ? "1" : parts[4];
                NPCChecks tempVar19(CheckType::CheckMon, {parts[1], parts[2], parts[3], tempString});
                CheckList.push_back(&tempVar19);

        }
//ORIGINAL LINE: case "CHECKEXACTMON":
        else if (StringHelper::toUpper(parts[0]) == "CHECKEXACTMON")
        {
                if (parts.size() < 5)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                tempString = parts.size() < 6 ? "1" : parts[5];
                NPCChecks tempVar20(CheckType::CheckExactMon, {parts[1], parts[2], parts[3], parts[4], tempString});
                CheckList.push_back(&tempVar20);

        }
//ORIGINAL LINE: case "RANDOM":
        else if (StringHelper::toUpper(parts[0]) == "RANDOM")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar21(CheckType::Random, {parts[1]});
                CheckList.push_back(&tempVar21);

        }
//ORIGINAL LINE: case "GROUPLEADER":
        else if (StringHelper::toUpper(parts[0]) == "GROUPLEADER")
        {
                NPCChecks tempVar22(CheckType::Groupleader);
                CheckList.push_back(&tempVar22);

        }
//ORIGINAL LINE: case "GROUPCOUNT":
        else if (StringHelper::toUpper(parts[0]) == "GROUPCOUNT")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar23(CheckType::GroupCount, {parts[1], parts[2]});
                CheckList.push_back(&tempVar23);

        }
//ORIGINAL LINE: case "GROUPCHECKNEARBY":
        else if (StringHelper::toUpper(parts[0]) == "GROUPCHECKNEARBY")
        {
                NPCChecks tempVar24(CheckType::GroupCheckNearby);
                CheckList.push_back(&tempVar24);

        }
//ORIGINAL LINE: case "PETCOUNT":
        else if (StringHelper::toUpper(parts[0]) == "PETCOUNT")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar25(CheckType::PetCount, {parts[1], parts[2]});
                CheckList.push_back(&tempVar25);

        }
//ORIGINAL LINE: case "PETLEVEL":
        else if (StringHelper::toUpper(parts[0]) == "PETLEVEL")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar26(CheckType::PetLevel, {parts[1], parts[2]});
                CheckList.push_back(&tempVar26);

        }
//ORIGINAL LINE: case "CHECKCALC":
        else if (StringHelper::toUpper(parts[0]) == "CHECKCALC")
        {
                if (parts.size() < 4)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }
                NPCChecks tempVar27(CheckType::CheckCalc, {parts[1], parts[2], parts[3]});
                CheckList.push_back(&tempVar27);

        }
//ORIGINAL LINE: case "INGUILD":
        else if (StringHelper::toUpper(parts[0]) == "INGUILD")
        {
                std::string guildName = "";

                if (parts.size() > 1)
                {
                    guildName = parts[1];
                }

                NPCChecks tempVar28(CheckType::InGuild, {guildName});
                CheckList.push_back(&tempVar28);

        }
//ORIGINAL LINE: case "CHECKQUEST":
        else if (StringHelper::toUpper(parts[0]) == "CHECKQUEST")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar29(CheckType::CheckQuest, {parts[1], parts[2]});
                CheckList.push_back(&tempVar29);
        }
//ORIGINAL LINE: case "CHECKRELATIONSHIP":
        else if (StringHelper::toUpper(parts[0]) == "CHECKRELATIONSHIP")
        {
                NPCChecks tempVar30(CheckType::CheckRelationship);
                CheckList.push_back(&tempVar30);
        }
//ORIGINAL LINE: case "CHECKWEDDINGRING":
        else if (StringHelper::toUpper(parts[0]) == "CHECKWEDDINGRING")
        {
                NPCChecks tempVar31(CheckType::CheckWeddingRing);
                CheckList.push_back(&tempVar31);

        }
//ORIGINAL LINE: case "CHECKPET":
        else if (StringHelper::toUpper(parts[0]) == "CHECKPET")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar32(CheckType::CheckPet, {parts[1]});
                CheckList.push_back(&tempVar32);

        }
//ORIGINAL LINE: case "HASBAGSPACE":
        else if (StringHelper::toUpper(parts[0]) == "HASBAGSPACE")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar33(CheckType::HasBagSpace, {parts[1], parts[2]});
                CheckList.push_back(&tempVar33);
        }
//ORIGINAL LINE: case "ISNEWHUMAN":
        else if (StringHelper::toUpper(parts[0]) == "ISNEWHUMAN")
        {
                NPCChecks tempVar34(CheckType::IsNewHuman);
                CheckList.push_back(&tempVar34);
        }
//ORIGINAL LINE: case "CHECKCONQUEST":
        else if (StringHelper::toUpper(parts[0]) == "CHECKCONQUEST")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar35(CheckType::CheckConquest, {parts[1]});
                CheckList.push_back(&tempVar35);
        }
//ORIGINAL LINE: case "AFFORDGUARD":
        else if (StringHelper::toUpper(parts[0]) == "AFFORDGUARD")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar36(CheckType::AffordGuard, {parts[1], parts[2]});
                CheckList.push_back(&tempVar36);
        }
//ORIGINAL LINE: case "AFFORDGATE":
        else if (StringHelper::toUpper(parts[0]) == "AFFORDGATE")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar37(CheckType::AffordGate, {parts[1], parts[2]});
                CheckList.push_back(&tempVar37);
        }
//ORIGINAL LINE: case "AFFORDWALL":
        else if (StringHelper::toUpper(parts[0]) == "AFFORDWALL")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar38(CheckType::AffordWall, {parts[1], parts[2]});
                CheckList.push_back(&tempVar38);
        }
//ORIGINAL LINE: case "AFFORDSIEGE":
        else if (StringHelper::toUpper(parts[0]) == "AFFORDSIEGE")
        {
                if (parts.size() < 3)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar39(CheckType::AffordSiege, {parts[1], parts[2]});
                CheckList.push_back(&tempVar39);
        }
//ORIGINAL LINE: case "CHECKPERMISSION":
        else if (StringHelper::toUpper(parts[0]) == "CHECKPERMISSION")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar40(CheckType::CheckPermission, {parts[1]});
                CheckList.push_back(&tempVar40);
        }
//ORIGINAL LINE: case "CONQUESTAVAILABLE":
        else if (StringHelper::toUpper(parts[0]) == "CONQUESTAVAILABLE")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar41(CheckType::ConquestAvailable, {parts[1]});
                CheckList.push_back(&tempVar41);
        }
//ORIGINAL LINE: case "CONQUESTOWNER":
        else if (StringHelper::toUpper(parts[0]) == "CONQUESTOWNER")
        {
                if (parts.size() < 2)
                {
                    delete regexQuote;
                    delete regexFlag;
                    return;
                }

                NPCChecks tempVar42(CheckType::ConquestOwner, {parts[1]});
                CheckList.push_back(&tempVar42);
        }

        delete regexQuote;
        delete regexFlag;
    }

    void NPCSegment::ParseAct(std::vector<NPCActions*> &acts, const std::string &line)
    {
        auto parts = line.Split(std::vector<char> {' '}, StringSplitOptions::RemoveEmptyEntries);

        parts = ParseArguments(parts);

        if (parts.empty())
        {
            return;
        }

        std::string fileName;
        auto regexQuote = new Regex("\"([^\"]*)\"");
        auto regexFlag = new Regex(R"(\[(.*?)\])");

        Match *quoteMatch = nullptr;

//C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic:
//        switch (parts[0].ToUpper())
//ORIGINAL LINE: case "MOVE":
        if (StringHelper::toUpper(parts[0]) == "MOVE")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                std::string tempx = parts.size() > 3 ? parts[2] : "0";
                std::string tempy = parts.size() > 3 ? parts[3] : "0";

                NPCActions tempVar(ActionType::Move, {parts[1], tempx, tempy});
                acts.push_back(&tempVar);

        }
//ORIGINAL LINE: case "INSTANCEMOVE":
        else if (StringHelper::toUpper(parts[0]) == "INSTANCEMOVE")
        {
                if (parts.size() < 5)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar2(ActionType::InstanceMove, {parts[1], parts[2], parts[3], parts[4]});
                acts.push_back(&tempVar2);

        }
//ORIGINAL LINE: case "GIVEGOLD":
        else if (StringHelper::toUpper(parts[0]) == "GIVEGOLD")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar3(ActionType::GiveGold, {parts[1]});
                acts.push_back(&tempVar3);

        }
//ORIGINAL LINE: case "TAKEGOLD":
        else if (StringHelper::toUpper(parts[0]) == "TAKEGOLD")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar4(ActionType::TakeGold, {parts[1]});
                acts.push_back(&tempVar4);
        }
//ORIGINAL LINE: case "GIVEGUILDGOLD":
        else if (StringHelper::toUpper(parts[0]) == "GIVEGUILDGOLD")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar5(ActionType::GiveGuildGold, {parts[1]});
                acts.push_back(&tempVar5);
        }
//ORIGINAL LINE: case "TAKEGUILDGOLD":
        else if (StringHelper::toUpper(parts[0]) == "TAKEGUILDGOLD")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar6(ActionType::TakeGuildGold, {parts[1]});
                acts.push_back(&tempVar6);
        }
//ORIGINAL LINE: case "GIVECREDIT":
        else if (StringHelper::toUpper(parts[0]) == "GIVECREDIT")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar7(ActionType::GiveCredit, {parts[1]});
                acts.push_back(&tempVar7);
        }
//ORIGINAL LINE: case "TAKECREDIT":
        else if (StringHelper::toUpper(parts[0]) == "TAKECREDIT")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar8(ActionType::TakeCredit, {parts[1]});
                acts.push_back(&tempVar8);

        }
//ORIGINAL LINE: case "GIVEPEARLS":
        else if (StringHelper::toUpper(parts[0]) == "GIVEPEARLS")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar9(ActionType::GivePearls, {parts[1]});
                acts.push_back(&tempVar9);

        }
//ORIGINAL LINE: case "TAKEPEARLS":
        else if (StringHelper::toUpper(parts[0]) == "TAKEPEARLS")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar10(ActionType::TakePearls, {parts[1]});
                acts.push_back(&tempVar10);

        }
//ORIGINAL LINE: case "GIVEITEM":
        else if (StringHelper::toUpper(parts[0]) == "GIVEITEM")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                std::string count = parts.size() < 3 ? "" : parts[2];
                NPCActions tempVar11(ActionType::GiveItem, {parts[1], count});
                acts.push_back(&tempVar11);

        }
//ORIGINAL LINE: case "TAKEITEM":
        else if (StringHelper::toUpper(parts[0]) == "TAKEITEM")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                count = parts.size() < 3 ? "" : parts[2];
                std::string dura = parts.size() > 3 ? parts[3] : "";

                NPCActions tempVar12(ActionType::TakeItem, {parts[1], count, dura});
                acts.push_back(&tempVar12);

        }
//ORIGINAL LINE: case "GIVEEXP":
        else if (StringHelper::toUpper(parts[0]) == "GIVEEXP")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar13(ActionType::GiveExp, {parts[1]});
                acts.push_back(&tempVar13);

        }
//ORIGINAL LINE: case "GIVEPET":
        else if (StringHelper::toUpper(parts[0]) == "GIVEPET")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                std::string petcount = parts.size() > 2 ? parts[2] : "1";
                std::string petlevel = parts.size() > 3 ? parts[3] : "0";

                NPCActions tempVar14(ActionType::GivePet, {parts[1], petcount, petlevel});
                acts.push_back(&tempVar14);
        }
//ORIGINAL LINE: case "REMOVEPET":
        else if (StringHelper::toUpper(parts[0]) == "REMOVEPET")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar15(ActionType::RemovePet, {parts[1]});
                acts.push_back(&tempVar15);
        }
//ORIGINAL LINE: case "CLEARPETS":
        else if (StringHelper::toUpper(parts[0]) == "CLEARPETS")
        {
                NPCActions tempVar16(ActionType::ClearPets);
                acts.push_back(&tempVar16);

        }
//ORIGINAL LINE: case "GOTO":
        else if (StringHelper::toUpper(parts[0]) == "GOTO")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar17(ActionType::Goto, {parts[1]});
                acts.push_back(&tempVar17);

        }
//ORIGINAL LINE: case "CALL":
        else if (StringHelper::toUpper(parts[0]) == "CALL")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                std::string listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                fileName = FileSystem::combine(Settings::NPCPath, listPath + ".txt");

                if (!FileSystem::fileExists(fileName))
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                auto script = NPCScript::GetOrAdd(0, listPath, NPCScriptType::Called);

                Page->ScriptCalls.push_back(script->ScriptID);

                NPCActions tempVar18(ActionType::Call, {std::to_string(script->ScriptID)});
                acts.push_back(&tempVar18);

        }
//ORIGINAL LINE: case "BREAK":
        else if (StringHelper::toUpper(parts[0]) == "BREAK")
        {
                NPCActions tempVar19(ActionType::Break);
                acts.push_back(&tempVar19);

            //cant use stored var
        }
//ORIGINAL LINE: case "ADDNAMELIST":
        else if (StringHelper::toUpper(parts[0]) == "ADDNAMELIST")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                fileName = FileSystem::combine(Settings::NameListPath, listPath);

                std::string sDirectory = FileSystem::getDirectoryName(fileName);
                FileSystem::createDirectory(sDirectory);

                if (!FileSystem::fileExists(fileName))
                {
                    File::Create(fileName)->Close();
                }

                NPCActions tempVar20(ActionType::AddNameList, {fileName});
                acts.push_back(&tempVar20);

            //cant use stored var
        }
//ORIGINAL LINE: case "ADDGUILDNAMELIST":
        else if (StringHelper::toUpper(parts[0]) == "ADDGUILDNAMELIST")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                fileName = FileSystem::combine(Settings::NameListPath, listPath);

                sDirectory = FileSystem::getDirectoryName(fileName);
                FileSystem::createDirectory(sDirectory);

                if (!FileSystem::fileExists(fileName))
                {
                    File::Create(fileName)->Close();
                }

                NPCActions tempVar21(ActionType::AddGuildNameList, {fileName});
                acts.push_back(&tempVar21);
            //cant use stored var
        }
//ORIGINAL LINE: case "DELNAMELIST":
        else if (StringHelper::toUpper(parts[0]) == "DELNAMELIST")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                fileName = FileSystem::combine(Settings::NameListPath, listPath);

                sDirectory = FileSystem::getDirectoryName(fileName);
                FileSystem::createDirectory(sDirectory);

                if (FileSystem::fileExists(fileName))
                {
                    NPCActions tempVar22(ActionType::DelNameList, {fileName});
                    acts.push_back(&tempVar22);
                }

            //cant use stored var
        }
//ORIGINAL LINE: case "DELGUILDNAMELIST":
        else if (StringHelper::toUpper(parts[0]) == "DELGUILDNAMELIST")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                fileName = FileSystem::combine(Settings::NameListPath, listPath);

                sDirectory = FileSystem::getDirectoryName(fileName);
                FileSystem::createDirectory(sDirectory);

                if (FileSystem::fileExists(fileName))
                {
                    NPCActions tempVar23(ActionType::DelGuildNameList, {fileName});
                    acts.push_back(&tempVar23);
                }
            //cant use stored var
        }
//ORIGINAL LINE: case "CLEARNAMELIST":
        else if (StringHelper::toUpper(parts[0]) == "CLEARNAMELIST")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                fileName = FileSystem::combine(Settings::NameListPath, listPath);

                sDirectory = FileSystem::getDirectoryName(fileName);
                FileSystem::createDirectory(sDirectory);

                if (FileSystem::fileExists(fileName))
                {
                    NPCActions tempVar24(ActionType::ClearNameList, {fileName});
                    acts.push_back(&tempVar24);
                }
            //cant use stored var
        }
//ORIGINAL LINE: case "CLEARGUILDNAMELIST":
        else if (StringHelper::toUpper(parts[0]) == "CLEARGUILDNAMELIST")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                listPath = parts[1];

                if (quoteMatch->Success)
                {
                    listPath = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                fileName = FileSystem::combine(Settings::NameListPath, listPath);

                sDirectory = FileSystem::getDirectoryName(fileName);
                FileSystem::createDirectory(sDirectory);

                if (FileSystem::fileExists(fileName))
                {
                    NPCActions tempVar25(ActionType::ClearGuildNameList, {fileName});
                    acts.push_back(&tempVar25);
                }

        }
//ORIGINAL LINE: case "GIVEHP":
        else if (StringHelper::toUpper(parts[0]) == "GIVEHP")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar26(ActionType::GiveHP, {parts[1]});
                acts.push_back(&tempVar26);

        }
//ORIGINAL LINE: case "GIVEMP":
        else if (StringHelper::toUpper(parts[0]) == "GIVEMP")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar27(ActionType::GiveMP, {parts[1]});
                acts.push_back(&tempVar27);

        }
//ORIGINAL LINE: case "CHANGELEVEL":
        else if (StringHelper::toUpper(parts[0]) == "CHANGELEVEL")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar28(ActionType::ChangeLevel, {parts[1]});
                acts.push_back(&tempVar28);

        }
//ORIGINAL LINE: case "SETPKPOINT":
        else if (StringHelper::toUpper(parts[0]) == "SETPKPOINT")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar29(ActionType::SetPkPoint, {parts[1]});
                acts.push_back(&tempVar29);

        }
//ORIGINAL LINE: case "REDUCEPKPOINT":
        else if (StringHelper::toUpper(parts[0]) == "REDUCEPKPOINT")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar30(ActionType::ReducePkPoint, {parts[1]});
                acts.push_back(&tempVar30);

        }
//ORIGINAL LINE: case "INCREASEPKPOINT":
        else if (StringHelper::toUpper(parts[0]) == "INCREASEPKPOINT")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar31(ActionType::IncreasePkPoint, {parts[1]});
                acts.push_back(&tempVar31);

        }
//ORIGINAL LINE: case "CHANGEGENDER":
        else if (StringHelper::toUpper(parts[0]) == "CHANGEGENDER")
        {
                NPCActions tempVar32(ActionType::ChangeGender);
                acts.push_back(&tempVar32);

        }
//ORIGINAL LINE: case "CHANGECLASS":
        else if (StringHelper::toUpper(parts[0]) == "CHANGECLASS")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar33(ActionType::ChangeClass, {parts[1]});
                acts.push_back(&tempVar33);

        }
//ORIGINAL LINE: case "CHANGEHAIR":
        else if (StringHelper::toUpper(parts[0]) == "CHANGEHAIR")
        {
                if (parts.size() < 2)
                {
                    NPCActions tempVar34(ActionType::ChangeHair);
                    acts.push_back(&tempVar34);
                }
                else
                {
                    NPCActions tempVar35(ActionType::ChangeHair, {parts[1]});
                    acts.push_back(&tempVar35);
                }

        }
//ORIGINAL LINE: case "LOCALMESSAGE":
        else if (StringHelper::toUpper(parts[0]) == "LOCALMESSAGE")
        {
                auto match = regexQuote->Match(line);
                if (match->Success)
                {
                    auto message = match->Groups[1]->Captures[0]->Value;

                    auto last = parts.size()() - 1;
                    NPCActions tempVar36(ActionType::LocalMessage, {message, parts[last]});
                    acts.push_back(&tempVar36);
                }

        }
//ORIGINAL LINE: case "GLOBALMESSAGE":
        else if (StringHelper::toUpper(parts[0]) == "GLOBALMESSAGE")
        {
                match = regexQuote->Match(line);
                if (match->Success)
                {
                    auto message = match->Groups[1]->Captures[0]->Value;

                    auto last = parts.size()() - 1;
                    NPCActions tempVar37(ActionType::GlobalMessage, {message, parts[last]});
                    acts.push_back(&tempVar37);
                }

        }
//ORIGINAL LINE: case "GIVESKILL":
        else if (StringHelper::toUpper(parts[0]) == "GIVESKILL")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                std::string spelllevel = parts.size() > 2 ? parts[2] : "0";
                NPCActions tempVar38(ActionType::GiveSkill, {parts[1], spelllevel});
                acts.push_back(&tempVar38);

        }
//ORIGINAL LINE: case "REMOVESKILL":
        else if (StringHelper::toUpper(parts[0]) == "REMOVESKILL")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar39(ActionType::RemoveSkill, {parts[1]});
                acts.push_back(&tempVar39);

            //cant use stored var
        }
//ORIGINAL LINE: case "SET":
        else if (StringHelper::toUpper(parts[0]) == "SET")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                match = regexFlag->Match(parts[1]);
                if (match->Success)
                {
                    std::string flagIndex = match->Groups[1]->Captures[0]->Value;
                    NPCActions tempVar40(ActionType::Set, {flagIndex, parts[2]});
                    acts.push_back(&tempVar40);
                }

        }
//ORIGINAL LINE: case "PARAM1":
        else if (StringHelper::toUpper(parts[0]) == "PARAM1")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                std::string instanceId = parts.size() < 3 ? "1" : parts[2];
                NPCActions tempVar41(ActionType::Param1, {parts[1], instanceId});
                acts.push_back(&tempVar41);

        }
//ORIGINAL LINE: case "PARAM2":
        else if (StringHelper::toUpper(parts[0]) == "PARAM2")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar42(ActionType::Param2, {parts[1]});
                acts.push_back(&tempVar42);

        }
//ORIGINAL LINE: case "PARAM3":
        else if (StringHelper::toUpper(parts[0]) == "PARAM3")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar43(ActionType::Param3, {parts[1]});
                acts.push_back(&tempVar43);

        }
//ORIGINAL LINE: case "MONGEN":
        else if (StringHelper::toUpper(parts[0]) == "MONGEN")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                count = parts.size() < 3 ? "1" : parts[2];
                NPCActions tempVar44(ActionType::Mongen, {parts[1], count});
                acts.push_back(&tempVar44);

        }
//ORIGINAL LINE: case "TIMERECALL":
        else if (StringHelper::toUpper(parts[0]) == "TIMERECALL")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                std::string page = parts.size() > 2 ? parts[2] : "";

                NPCActions tempVar45(ActionType::TimeRecall, {parts[1], page});
                acts.push_back(&tempVar45);

        }
//ORIGINAL LINE: case "TIMERECALLGROUP":
        else if (StringHelper::toUpper(parts[0]) == "TIMERECALLGROUP")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                page = parts.size() > 2 ? parts[2] : "";

                NPCActions tempVar46(ActionType::TimeRecallGroup, {parts[1], page});
                acts.push_back(&tempVar46);

        }
//ORIGINAL LINE: case "BREAKTIMERECALL":
        else if (StringHelper::toUpper(parts[0]) == "BREAKTIMERECALL")
        {
                NPCActions tempVar47(ActionType::BreakTimeRecall);
                acts.push_back(&tempVar47);

        }
//ORIGINAL LINE: case "DELAYGOTO":
        else if (StringHelper::toUpper(parts[0]) == "DELAYGOTO")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar48(ActionType::DelayGoto, {parts[1], parts[2]});
                acts.push_back(&tempVar48);

        }
//ORIGINAL LINE: case "MONCLEAR":
        else if (StringHelper::toUpper(parts[0]) == "MONCLEAR")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                instanceId = parts.size() < 3 ? "1" : parts[2];

                std::string mobName = parts.size() < 4 ? "" : parts[3];

                NPCActions tempVar49(ActionType::MonClear, {parts[1], instanceId, mobName});
                acts.push_back(&tempVar49);

        }
//ORIGINAL LINE: case "GROUPRECALL":
        else if (StringHelper::toUpper(parts[0]) == "GROUPRECALL")
        {
                NPCActions tempVar50(ActionType::GroupRecall);
                acts.push_back(&tempVar50);

        }
//ORIGINAL LINE: case "GROUPTELEPORT":
        else if (StringHelper::toUpper(parts[0]) == "GROUPTELEPORT")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                std::string x;
                std::string y;

                if (parts.size() == 4)
                {
                    instanceId = "1";
                    x = parts[2];
                    y = parts[3];
                }
                else
                {
                    instanceId = parts.size() < 3 ? "1" : parts[2];
                    x = parts.size() < 4 ? "0" : parts[3];
                    y = parts.size() < 5 ? "0" : parts[4];
                }

                NPCActions tempVar51(ActionType::GroupTeleport, {parts[1], instanceId, x, y});
                acts.push_back(&tempVar51);

        }
//ORIGINAL LINE: case "MOV":
        else if (StringHelper::toUpper(parts[0]) == "MOV")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                match = Regex::Match(parts[1], R"([A-Z][0-9])", RegexOptions::IgnoreCase);

                quoteMatch = regexQuote->Match(line);

                std::string valueToStore = parts[2];

                if (quoteMatch->Success)
                {
                    valueToStore = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                if (match->Success)
                {
                    NPCActions tempVar52(ActionType::Mov, {parts[1], valueToStore});
                    acts.push_back(&tempVar52);
                }

        }
//ORIGINAL LINE: case "CALC":
        else if (StringHelper::toUpper(parts[0]) == "CALC")
        {
                if (parts.size() < 4)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                match = Regex::Match(parts[1], R"([A-Z][0-9])", RegexOptions::IgnoreCase);

                quoteMatch = regexQuote->Match(line);

                valueToStore = parts[3];

                if (quoteMatch->Success)
                {
                    valueToStore = quoteMatch->Groups[1]->Captures[0]->Value;
                }

                if (match->Success)
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the .NET String 'Insert' method unless assigning to the string instance:
                    NPCActions tempVar53(ActionType::Calc, {"%" + parts[1], parts[2], valueToStore, parts[1].Insert(1, "-")});
                    acts.push_back(&tempVar53);
                }

        }
//ORIGINAL LINE: case "GIVEBUFF":
        else if (StringHelper::toUpper(parts[0]) == "GIVEBUFF")
        {
                if (parts.size() < 4)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                std::string visible = "";
                std::string infinite = "";
                std::string stackable = "";

                if (parts.size() > 3)
                {
                    visible = parts[3];
                }
                if (parts.size() > 4)
                {
                    infinite = parts[4];
                }
                if (parts.size() > 5)
                {
                    stackable = parts[5];
                }

                NPCActions tempVar54(ActionType::GiveBuff, {parts[1], parts[2], visible, infinite, stackable});
                acts.push_back(&tempVar54);

        }
//ORIGINAL LINE: case "REMOVEBUFF":
        else if (StringHelper::toUpper(parts[0]) == "REMOVEBUFF")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar55(ActionType::RemoveBuff, {parts[1]});
                acts.push_back(&tempVar55);

        }
//ORIGINAL LINE: case "ADDTOGUILD":
        else if (StringHelper::toUpper(parts[0]) == "ADDTOGUILD")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar56(ActionType::AddToGuild, {parts[1]});
                acts.push_back(&tempVar56);

        }
//ORIGINAL LINE: case "REMOVEFROMGUILD":
        else if (StringHelper::toUpper(parts[0]) == "REMOVEFROMGUILD")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar57(ActionType::RemoveFromGuild, {parts[1]});
                acts.push_back(&tempVar57);

        }
//ORIGINAL LINE: case "REFRESHEFFECTS":
        else if (StringHelper::toUpper(parts[0]) == "REFRESHEFFECTS")
        {
                NPCActions tempVar58(ActionType::RefreshEffects);
                acts.push_back(&tempVar58);

        }
//ORIGINAL LINE: case "CANGAINEXP":
        else if (StringHelper::toUpper(parts[0]) == "CANGAINEXP")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar59(ActionType::CanGainExp, {parts[1]});
                acts.push_back(&tempVar59);

        }
//ORIGINAL LINE: case "COMPOSEMAIL":
        else if (StringHelper::toUpper(parts[0]) == "COMPOSEMAIL")
        {
                match = regexQuote->Match(line);
                if (match->Success)
                {
                    auto message = match->Groups[1]->Captures[0]->Value;

                    auto last = parts.size()() - 1;
                    NPCActions tempVar60(ActionType::ComposeMail, {message, parts[last]});
                    acts.push_back(&tempVar60);
                }

        }
//ORIGINAL LINE: case "ADDMAILGOLD":
        else if (StringHelper::toUpper(parts[0]) == "ADDMAILGOLD")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar61(ActionType::AddMailGold, {parts[1]});
                acts.push_back(&tempVar61);

        }
//ORIGINAL LINE: case "ADDMAILITEM":
        else if (StringHelper::toUpper(parts[0]) == "ADDMAILITEM")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar62(ActionType::AddMailItem, {parts[1], parts[2]});
                acts.push_back(&tempVar62);

        }
//ORIGINAL LINE: case "SENDMAIL":
        else if (StringHelper::toUpper(parts[0]) == "SENDMAIL")
        {
                NPCActions tempVar63(ActionType::SendMail);
                acts.push_back(&tempVar63);

        }
//ORIGINAL LINE: case "GROUPGOTO":
        else if (StringHelper::toUpper(parts[0]) == "GROUPGOTO")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar64(ActionType::GroupGoto, {parts[1]});
                acts.push_back(&tempVar64);

        }
//ORIGINAL LINE: case "ENTERMAP":
        else if (StringHelper::toUpper(parts[0]) == "ENTERMAP")
        {
                NPCActions tempVar65(ActionType::EnterMap);
                acts.push_back(&tempVar65);
        }
//ORIGINAL LINE: case "MAKEWEDDINGRING":
        else if (StringHelper::toUpper(parts[0]) == "MAKEWEDDINGRING")
        {
                NPCActions tempVar66(ActionType::MakeWeddingRing);
                acts.push_back(&tempVar66);
        }
//ORIGINAL LINE: case "FORCEDIVORCE":
        else if (StringHelper::toUpper(parts[0]) == "FORCEDIVORCE")
        {
                NPCActions tempVar67(ActionType::ForceDivorce);
                acts.push_back(&tempVar67);

        }
//ORIGINAL LINE: case "LOADVALUE":
        else if (StringHelper::toUpper(parts[0]) == "LOADVALUE")
        {
                if (parts.size() < 5)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                quoteMatch = regexQuote->Match(line);

                if (quoteMatch->Success)
                {
                    fileName = FileSystem::combine(Settings::ValuePath, quoteMatch->Groups[1]->Captures[0]->Value);

                    std::string group = parts[parts.size() - 2];
                    std::string key = parts[parts.size() - 1];

                    sDirectory = FileSystem::getDirectoryName(fileName);
                    FileSystem::createDirectory(sDirectory);

                    if (!FileSystem::fileExists(fileName))
                    {
                        File::Create(fileName)->Close();
                    }

                    NPCActions tempVar68(ActionType::LoadValue, {parts[1], fileName, group, key});
                    acts.push_back(&tempVar68);
                }

        }
//ORIGINAL LINE: case "SAVEVALUE":
        else if (StringHelper::toUpper(parts[0]) == "SAVEVALUE")
        {
                if (parts.size() < 5)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                MatchCollection *matchCol = regexQuote->Matches(line);

                if (matchCol->Count > 0 && matchCol[0]->Success)
                {
                    fileName = FileSystem::combine(Settings::ValuePath, matchCol[0]->Groups[1].Captures[0]->Value);

                    std::string value = parts[parts.size() - 1];

                    if (matchCol->Count > 1 && matchCol[1]->Success)
                    {
                        value = matchCol[1]->Groups[1].Captures[0]->Value;
                    }

                    std::vector<std::string> newParts = StringHelper::split(StringHelper::trim(StringHelper::replace(StringHelper::replace(line, value, ""), "\"", "")), ' ');

                    std::string group = newParts[newParts.size() - 2];
                    std::string key = newParts[newParts.size() - 1];

                    sDirectory = FileSystem::getDirectoryName(fileName);
                    FileSystem::createDirectory(sDirectory);

                    if (!FileSystem::fileExists(fileName))
                    {
                        File::Create(fileName)->Close();
                    }

                    NPCActions tempVar69(ActionType::SaveValue, {fileName, group, key, value});
                    acts.push_back(&tempVar69);
                }
        }
//ORIGINAL LINE: case "CONQUESTGUARD":
        else if (StringHelper::toUpper(parts[0]) == "CONQUESTGUARD")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar70(ActionType::ConquestGuard, {parts[1], parts[2]});
                acts.push_back(&tempVar70);
        }
//ORIGINAL LINE: case "CONQUESTGATE":
        else if (StringHelper::toUpper(parts[0]) == "CONQUESTGATE")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar71(ActionType::ConquestGate, {parts[1], parts[2]});
                acts.push_back(&tempVar71);
        }
//ORIGINAL LINE: case "CONQUESTWALL":
        else if (StringHelper::toUpper(parts[0]) == "CONQUESTWALL")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar72(ActionType::ConquestWall, {parts[1], parts[2]});
                acts.push_back(&tempVar72);
        }
//ORIGINAL LINE: case "TAKECONQUESTGOLD":
        else if (StringHelper::toUpper(parts[0]) == "TAKECONQUESTGOLD")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar73(ActionType::TakeConquestGold, {parts[1]});
                acts.push_back(&tempVar73);
        }
//ORIGINAL LINE: case "SETCONQUESTRATE":
        else if (StringHelper::toUpper(parts[0]) == "SETCONQUESTRATE")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar74(ActionType::SetConquestRate, {parts[1], parts[2]});
                acts.push_back(&tempVar74);
        }
//ORIGINAL LINE: case "STARTCONQUEST":
        else if (StringHelper::toUpper(parts[0]) == "STARTCONQUEST")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar75(ActionType::StartConquest, {parts[1], parts[2]});
                acts.push_back(&tempVar75);
        }
//ORIGINAL LINE: case "SCHEDULECONQUEST":
        else if (StringHelper::toUpper(parts[0]) == "SCHEDULECONQUEST")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar76(ActionType::ScheduleConquest, {parts[1]});
                acts.push_back(&tempVar76);
        }
//ORIGINAL LINE: case "OPENGATE":
        else if (StringHelper::toUpper(parts[0]) == "OPENGATE")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar77(ActionType::OpenGate, {parts[1], parts[2]});
                acts.push_back(&tempVar77);
        }
//ORIGINAL LINE: case "CLOSEGATE":
        else if (StringHelper::toUpper(parts[0]) == "CLOSEGATE")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar78(ActionType::CloseGate, {parts[1], parts[2]});
                acts.push_back(&tempVar78);
        }
//ORIGINAL LINE: case "OPENBROWSER":
        else if (StringHelper::toUpper(parts[0]) == "OPENBROWSER")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar79(ActionType::OpenBrowser, {parts[1]});
                acts.push_back(&tempVar79);
        }
//ORIGINAL LINE: case "GETRANDOMTEXT":
        else if (StringHelper::toUpper(parts[0]) == "GETRANDOMTEXT")
        {
                if (parts.size() < 3)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                match = Regex::Match(parts[2], R"([A-Z][0-9])", RegexOptions::IgnoreCase);
                if (match->Success)
                {
                    NPCActions tempVar80(ActionType::GetRandomText, {parts[1], parts[2]});
                    acts.push_back(&tempVar80);
                }
        }
//ORIGINAL LINE: case "PLAYSOUND":
        else if (StringHelper::toUpper(parts[0]) == "PLAYSOUND")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }
                NPCActions tempVar81(ActionType::PlaySound, {parts[1]});
                acts.push_back(&tempVar81);
        }
//ORIGINAL LINE: case "SETTIMER":
        else if (StringHelper::toUpper(parts[0]) == "SETTIMER")
        {
                if (parts.size() < 4)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar82(ActionType::SetTimer, {parts[1], parts[2], parts[3]});
                acts.push_back(&tempVar82);
        }
//ORIGINAL LINE: case "EXPIRETIMER":
        else if (StringHelper::toUpper(parts[0]) == "EXPIRETIMER")
        {
                if (parts.size() < 2)
                {
                    delete regexFlag;
                    delete regexQuote;
                    return;
                }

                NPCActions tempVar83(ActionType::ExpireTimer, {parts[1]});
                acts.push_back(&tempVar83);

        }
//ORIGINAL LINE: case "UNEQUIPITEM":
        else if (StringHelper::toUpper(parts[0]) == "UNEQUIPITEM")
        {
                auto type = "";

                if (parts.size() >= 2)
                {
                    type = parts[1];
                }

                NPCActions tempVar84(ActionType::UnequipItem, {type});
                acts.push_back(&tempVar84);
        }

        delete regexFlag;
        delete regexQuote;
    }

    std::vector<std::string> NPCSegment::ParseSay(PlayerObject *player, std::vector<std::string> &speech)
    {
        for (auto i = 0; i < speech.size(); i++)
        {
            auto parts = speech[i].Split(std::vector<char> {' '}, StringSplitOptions::RemoveEmptyEntries);

            if (parts.empty())
            {
                continue;
            }

            for (auto part : parts)
            {
                speech[i] = StringHelper::replace(speech[i], part, ReplaceValue(player, part));
            }
        }
        return speech;
    }

    std::string NPCSegment::ReplaceValue(PlayerObject *player, const std::string &param)
    {
        auto regex = new Regex(R"(\<\$(.*)\>)");
        auto varRegex = new Regex(R"((.*?)\(([A-Z][0-9])\))");
        auto oneValRegex = new Regex(R"((.*?)\(((.*?))\))");
        auto twoValRegex = new Regex(R"((.*?)\(((.*?),(.*?))\))");
        ConquestObject *Conquest;
        ConquestArcherObject *Archer;
        ConquestGateObject *Gate;
        ConquestWallObject *Wall;
        ConquestSiegeObject *Siege;

        auto match = regex->Match(param);

        if (!match->Success)
        {
            delete twoValRegex;
            delete oneValRegex;
            delete varRegex;
            delete regex;
            return param;
        }

        std::string innerMatch = StringHelper::toUpper(match->Groups[1]->Captures[0]->Value);

        Match *varMatch = varRegex->Match(innerMatch);
        Match *oneValMatch = oneValRegex->Match(innerMatch);
        Match *twoValMatch = twoValRegex->Match(innerMatch);

        if (varRegex->Match(innerMatch)->Success)
        {
            innerMatch = StringHelper::replace(innerMatch, StringHelper::toUpper(varMatch->Groups[2]->Captures[0]->Value), "");
        }
        else if (twoValRegex->Match(innerMatch)->Success)
        {
            innerMatch = StringHelper::replace(innerMatch, StringHelper::toUpper(twoValMatch->Groups[2]->Captures[0]->Value), "");
        }
        else if (oneValRegex->Match(innerMatch)->Success)
        {
            innerMatch = StringHelper::replace(innerMatch, StringHelper::toUpper(oneValMatch->Groups[2]->Captures[0]->Value), "");
        }

        std::string newValue = "";

//C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic:
//        switch (innerMatch)
//ORIGINAL LINE: case "MONSTERCOUNT()":
        if (innerMatch == "MONSTERCOUNT()")
        {
                Map *map = getEnvir()->GetMapByNameAndInstance(StringHelper::toUpper(oneValMatch->Groups[2]->Captures[0]->Value));
                newValue = map == nullptr ? "N/A" : std::to_string(map->MonsterCount);
        }
//ORIGINAL LINE: case "CONQUESTGUARD()":
        else if (innerMatch == "CONQUESTGUARD()")
        {
                auto val1 = FindVariable(player, "%" + StringHelper::toUpper(twoValMatch->Groups[3]->Captures[0]->Value));
                auto val2 = FindVariable(player, "%" + StringHelper::toUpper(twoValMatch->Groups[4]->Captures[0]->Value));

                int intVal1, intVal2;

                if (int::TryParse(StringHelper::replace(val1, "%", ""), intVal1) && int::TryParse(StringHelper::replace(val2, "%", ""), intVal2))
                {

                    Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any x)
                    {
                        return x::Info->Index == intVal1;
                    });
                    if (Conquest == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Not Found";
                    }

                    Archer = Conquest->ArcherList.FirstOrDefault([&] (std::any x)
                    {
                        return x->Index == intVal2;
                    });
                    if (Archer == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Not Found";
                    }

                    if (Archer->Info->Name == "" || Archer->Info->Name == "")
                    {
                        newValue = "Conquest Guard";
                    }
                    else
                    {
                        newValue = Archer->Info->Name;
                    }

                    if (Archer->GetRepairCost() == 0)
                    {
                        newValue += " - [ Still Alive ]";
                    }
                    else
                    {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                        newValue += " - [ " + Archer->GetRepairCost().ToString("#,##0") + " gold ]";
                    }
                }
        }
//ORIGINAL LINE: case "CONQUESTGATE()":
        else if (innerMatch == "CONQUESTGATE()")
        {
                val1 = FindVariable(player, "%" + StringHelper::toUpper(twoValMatch->Groups[3]->Captures[0]->Value));
                val2 = FindVariable(player, "%" + StringHelper::toUpper(twoValMatch->Groups[4]->Captures[0]->Value));

                if (int::TryParse(StringHelper::replace(val1, "%", ""), intVal1) && int::TryParse(StringHelper::replace(val2, "%", ""), intVal2))
                {
                    Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any x)
                    {
                        return x::Info->Index == intVal1;
                    });
                    if (Conquest == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Not Found";
                    }

                    Gate = Conquest->GateList.FirstOrDefault([&] (std::any x)
                    {
                        return x->Index == intVal2;
                    });
                    if (Gate == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Not Found";
                    }

                    if (Gate->Info->Name == "" || Gate->Info->Name == "")
                    {
                        newValue = "Conquest Gate";
                    }
                    else
                    {
                        newValue = Gate->Info->Name;
                    }

                    if (Gate->GetRepairCost() == 0)
                    {
                        newValue += " - [ No Repair Required ]";
                    }
                    else
                    {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                        newValue += " - [ " + Gate->GetRepairCost().ToString("#,##0") + " gold ]";
                    }
                }
        }
//ORIGINAL LINE: case "CONQUESTWALL()":
        else if (innerMatch == "CONQUESTWALL()")
        {
                val1 = FindVariable(player, "%" + StringHelper::toUpper(twoValMatch->Groups[3]->Captures[0]->Value));
                val2 = FindVariable(player, "%" + StringHelper::toUpper(twoValMatch->Groups[4]->Captures[0]->Value));

                if (int::TryParse(StringHelper::replace(val1, "%", ""), intVal1) && int::TryParse(StringHelper::replace(val2, "%", ""), intVal2))
                {
                    Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any x)
                    {
                        return x::Info->Index == intVal1;
                    });
                    if (Conquest == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Not Found";
                    }

                    Wall = Conquest->WallList.FirstOrDefault([&] (std::any x)
                    {
                        return x->Index == intVal2;
                    });
                    if (Wall == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Not Found";
                    }

                    if (Wall->Info->Name == "" || Wall->Info->Name == "")
                    {
                        newValue = "Conquest Wall";
                    }
                    else
                    {
                        newValue = Wall->Info->Name;
                    }

                    if (Wall->GetRepairCost() == 0)
                    {
                        newValue += " - [ No Repair Required ]";
                    }
                    else
                    {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                        newValue += " - [ " + Wall->GetRepairCost().ToString("#,##0") + " gold ]";
                    }
                }
        }
//ORIGINAL LINE: case "CONQUESTSIEGE()":
        else if (innerMatch == "CONQUESTSIEGE()")
        {
                val1 = FindVariable(player, "%" + StringHelper::toUpper(twoValMatch->Groups[3]->Captures[0]->Value));
                val2 = FindVariable(player, "%" + StringHelper::toUpper(twoValMatch->Groups[4]->Captures[0]->Value));

                if (int::TryParse(StringHelper::replace(val1, "%", ""), intVal1) && int::TryParse(StringHelper::replace(val2, "%", ""), intVal2))
                {
                    Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any x)
                    {
                        return x::Info->Index == intVal1;
                    });
                    if (Conquest == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Not Found";
                    }

                    Siege = Conquest->SiegeList.FirstOrDefault([&] (std::any x)
                    {
                        return x->Index == intVal2;
                    });
                    if (Siege == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Not Found";
                    }

                    if (Siege->Info->Name == "" || Siege->Info->Name == "")
                    {
                        newValue = "Conquest Siege";
                    }
                    else
                    {
                        newValue = Siege->Info->Name;
                    }

                    if (Siege->GetRepairCost() == 0)
                    {
                        newValue += " - [ Still Alive ]";
                    }
                    else
                    {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                        newValue += " - [ " + Siege->GetRepairCost().ToString("#,##0") + " gold ]";
                    }
                }
        }
//ORIGINAL LINE: case "CONQUESTOWNER()":
        else if (innerMatch == "CONQUESTOWNER()")
        {
                val1 = FindVariable(player, "%" + StringHelper::toUpper(oneValMatch->Groups[2]->Captures[0]->Value));

                if (int::TryParse(StringHelper::replace(val1, "%", ""), intVal1))
                {
                    Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any x)
                    {
                        return x::Info->Index == intVal1;
                    });
                    if (Conquest == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "";
                    }
                    if (Conquest->Guild == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "No Owner";
                    }

                    newValue = Conquest->Guild->Name;
                }
        }
//ORIGINAL LINE: case "CONQUESTGOLD()":
        else if (innerMatch == "CONQUESTGOLD()")
        {
                val1 = FindVariable(player, "%" + StringHelper::toUpper(oneValMatch->Groups[2]->Captures[0]->Value));

                if (int::TryParse(StringHelper::replace(val1, "%", ""), intVal1))
                {
                    Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any x)
                    {
                        return x::Info->Index == intVal1;
                    });
                    if (Conquest == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "";
                    }

                    newValue = std::to_string(Conquest->GoldStorage);
                }
        }
//ORIGINAL LINE: case "CONQUESTRATE()":
        else if (innerMatch == "CONQUESTRATE()")
        {
                val1 = FindVariable(player, "%" + StringHelper::toUpper(oneValMatch->Groups[2]->Captures[0]->Value));

                if (int::TryParse(StringHelper::replace(val1, "%", ""), intVal1))
                {
                    Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any x)
                    {
                        return x::Info->Index == intVal1;
                    });
                    if (Conquest == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "";
                    }

                    newValue = std::to_string(Conquest->npcRate) + "%";
                }
        }
//ORIGINAL LINE: case "CONQUESTSCHEDULE()":
        else if (innerMatch == "CONQUESTSCHEDULE()")
        {
                val1 = FindVariable(player, "%" + StringHelper::toUpper(oneValMatch->Groups[2]->Captures[0]->Value));

                if (int::TryParse(StringHelper::replace(val1, "%", ""), intVal1))
                {
                    Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any x)
                    {
                        return x::Info->Index == intVal1;
                    });
                    if (Conquest == nullptr)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "Conquest Not Found";
                    }
                    if (Conquest->AttackerID == -1)
                    {
                        delete twoValRegex;
                        delete oneValRegex;
                        delete varRegex;
                        delete regex;
                        return "No War Scheduled";
                    }

                    if (getEnvir()->GuildList.FirstOrDefault([&] (std::any x)
                    {
                        return x->Guildindex == Conquest->AttackerID;
                    }) == nullptr)
                    {
                        newValue = "No War Scheduled";
                    }
                    else
                    {
                        newValue = (getEnvir()->GuildList.FirstOrDefault([&] (std::any x)
                        {
                            return x->Guildindex == Conquest->AttackerID;
                        })->Name);
                    }
                }
        }
//ORIGINAL LINE: case "OUTPUT()":
        else if (innerMatch == "OUTPUT()")
        {
                newValue = FindVariable(player, "%" + StringHelper::toUpper(varMatch->Groups[2]->Captures[0]->Value));
        }
//ORIGINAL LINE: case "NPCNAME":
        else if (innerMatch == "NPCNAME")
        {
                for (int i = 0; i < player->getCurrentMap()->NPCs.size(); i++)
                {
                    NPCObject *ob = player->getCurrentMap()->NPCs[i];
                    if (ob->ObjectID != player->NPCObjectID)
                    {
                        continue;
                    }
                    newValue = StringHelper::replace(ob->getName(), "_", " ");
                }
        }
//ORIGINAL LINE: case "USERNAME":
        else if (innerMatch == "USERNAME")
        {
                newValue = player->getName();
        }
//ORIGINAL LINE: case "LEVEL":
        else if (innerMatch == "LEVEL")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->getLevel().ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "CLASS":
        else if (innerMatch == "CLASS")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->getClass().ToString();
        }
//ORIGINAL LINE: case "MAP":
        else if (innerMatch == "MAP")
        {
                newValue = player->getCurrentMap()->Info->FileName;
        }
//ORIGINAL LINE: case "X_COORD":
        else if (innerMatch == "X_COORD")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->getCurrentLocation()->X.ToString();
        }
//ORIGINAL LINE: case "Y_COORD":
        else if (innerMatch == "Y_COORD")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->getCurrentLocation()->Y.ToString();
        }
//ORIGINAL LINE: case "HP":
        else if (innerMatch == "HP")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->getHP().ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "MAXHP":
        else if (innerMatch == "MAXHP")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->Stats[Stat::HP].ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "MP":
        else if (innerMatch == "MP")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->getMP().ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "MAXMP":
        else if (innerMatch == "MAXMP")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->Stats[Stat::MP].ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "GAMEGOLD":
        else if (innerMatch == "GAMEGOLD")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->Account->Gold.ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "CREDIT":
        else if (innerMatch == "CREDIT")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = player->Account->Credit.ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "ARMOUR":
        else if (innerMatch == "ARMOUR")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Armour)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Armour)]->getFriendlyName() : "No Armour";
        }
//ORIGINAL LINE: case "WEAPON":
        else if (innerMatch == "WEAPON")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Weapon)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Weapon)]->getFriendlyName() : "No Weapon";
        }
//ORIGINAL LINE: case "RING_L":
        else if (innerMatch == "RING_L")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::RingL)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::RingL)]->getFriendlyName() : "No Ring";
        }
//ORIGINAL LINE: case "RING_R":
        else if (innerMatch == "RING_R")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::RingR)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::RingR)]->getFriendlyName() : "No Ring";
        }
//ORIGINAL LINE: case "BRACELET_L":
        else if (innerMatch == "BRACELET_L")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::BraceletL)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::BraceletL)]->getFriendlyName() : "No Bracelet";
        }
//ORIGINAL LINE: case "BRACELET_R":
        else if (innerMatch == "BRACELET_R")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::BraceletR)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::BraceletR)]->getFriendlyName() : "No Bracelet";
        }
//ORIGINAL LINE: case "NECKLACE":
        else if (innerMatch == "NECKLACE")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Necklace)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Necklace)]->getFriendlyName() : "No Necklace";
        }
//ORIGINAL LINE: case "BELT":
        else if (innerMatch == "BELT")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Belt)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Belt)]->getFriendlyName() : "No Belt";
        }
//ORIGINAL LINE: case "BOOTS":
        else if (innerMatch == "BOOTS")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Boots)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Boots)]->getFriendlyName() : "No Boots";
        }
//ORIGINAL LINE: case "HELMET":
        else if (innerMatch == "HELMET")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Helmet)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Helmet)]->getFriendlyName() : "No Helmet";
        }
//ORIGINAL LINE: case "AMULET":
        else if (innerMatch == "AMULET")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Amulet)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Amulet)]->getFriendlyName() : "No Amulet";
        }
//ORIGINAL LINE: case "STONE":
        else if (innerMatch == "STONE")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Stone)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Stone)]->getFriendlyName() : "No Stone";
        }
//ORIGINAL LINE: case "TORCH":
        else if (innerMatch == "TORCH")
        {
                newValue = player->Info->Equipment[static_cast<int>(EquipmentSlot::Torch)] != nullptr ? player->Info->Equipment[static_cast<int>(EquipmentSlot::Torch)]->getFriendlyName() : "No Torch";

        }
//ORIGINAL LINE: case "DATE":
        else if (innerMatch == "DATE")
        {
                newValue = DateTime::Now.ToShortDateString();
        }
//ORIGINAL LINE: case "USERCOUNT":
        else if (innerMatch == "USERCOUNT")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = getEnvir()->getPlayerCount().ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "PKPOINT":
        else if (innerMatch == "PKPOINT")
        {
                newValue = std::to_string(player->getPKPoints());
        }
//ORIGINAL LINE: case "GUILDWARTIME":
        else if (innerMatch == "GUILDWARTIME")
        {
                newValue = std::to_string(Settings::Guild_WarTime);
        }
//ORIGINAL LINE: case "GUILDWARFEE":
        else if (innerMatch == "GUILDWARFEE")
        {
                newValue = std::to_string(Settings::Guild_WarCost);

        }
//ORIGINAL LINE: case "PARCELAMOUNT":
        else if (innerMatch == "PARCELAMOUNT")
        {
                newValue = std::to_string(player->GetMailAwaitingCollectionAmount());
        }
//ORIGINAL LINE: case "GUILDNAME":
        else if (innerMatch == "GUILDNAME")
        {
                if (player->MyGuild == nullptr)
                {
                    delete twoValRegex;
                    delete oneValRegex;
                    delete varRegex;
                    delete regex;
                    return "No Guild";
                }
                else
                {
                    newValue = player->MyGuild->Name + " Guild";
                }

        }
        else
        {
                newValue = "";
        }

        if (newValue.empty())
        {
            delete twoValRegex;
            delete oneValRegex;
            delete varRegex;
            delete regex;
            return param;
        }

        delete twoValRegex;
        delete oneValRegex;
        delete varRegex;
        delete regex;
        return StringHelper::replace(param, match->Value, newValue);
    }

    std::string NPCSegment::ReplaceValue(MonsterObject *Monster, const std::string &param)
    {
        auto regex = new Regex(R"(\<\$(.*)\>)");
        auto varRegex = new Regex(R"((.*?)\(([A-Z][0-9])\))");

        auto match = regex->Match(param);

        if (!match->Success)
        {
            delete varRegex;
            delete regex;
            return param;
        }

        std::string innerMatch = StringHelper::toUpper(match->Groups[1]->Captures[0]->Value);

        Match *varMatch = varRegex->Match(innerMatch);

        if (varRegex->Match(innerMatch)->Success)
        {
            innerMatch = StringHelper::replace(innerMatch, StringHelper::toUpper(varMatch->Groups[2]->Captures[0]->Value), "");
        }

        std::string newValue = "";

//C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic:
//        switch (innerMatch)
//ORIGINAL LINE: case "OUTPUT()":
        if (innerMatch == "OUTPUT()")
        {
                newValue = FindVariable(Monster, "%" + StringHelper::toUpper(varMatch->Groups[2]->Captures[0]->Value));
        }
//ORIGINAL LINE: case "USERNAME":
        else if (innerMatch == "USERNAME")
        {
                newValue = Monster->getName();
        }
//ORIGINAL LINE: case "LEVEL":
        else if (innerMatch == "LEVEL")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = Monster->getLevel().ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "MAP":
        else if (innerMatch == "MAP")
        {
                newValue = Monster->getCurrentMap()->Info->FileName;
        }
//ORIGINAL LINE: case "X_COORD":
        else if (innerMatch == "X_COORD")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = Monster->getCurrentLocation()->X.ToString();
        }
//ORIGINAL LINE: case "Y_COORD":
        else if (innerMatch == "Y_COORD")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = Monster->getCurrentLocation()->Y.ToString();
        }
//ORIGINAL LINE: case "HP":
        else if (innerMatch == "HP")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = Monster->HP.ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "MAXHP":
        else if (innerMatch == "MAXHP")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = Monster->Stats[Stat::HP].ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "DATE":
        else if (innerMatch == "DATE")
        {
                newValue = DateTime::Now.ToShortDateString();
        }
//ORIGINAL LINE: case "USERCOUNT":
        else if (innerMatch == "USERCOUNT")
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                newValue = getEnvir()->getPlayerCount().ToString(CultureInfo::InvariantCulture);
        }
//ORIGINAL LINE: case "GUILDWARTIME":
        else if (innerMatch == "GUILDWARTIME")
        {
                newValue = std::to_string(Settings::Guild_WarTime);
        }
//ORIGINAL LINE: case "GUILDWARFEE":
        else if (innerMatch == "GUILDWARFEE")
        {
                newValue = std::to_string(Settings::Guild_WarCost);
        }
        else
        {
                newValue = "";
        }

        if (newValue.empty())
        {
            delete varRegex;
            delete regex;
            return param;
        }

        delete varRegex;
        delete regex;
        return StringHelper::replace(param, match->Value, newValue);
    }

    bool NPCSegment::Check()
    {
        auto failed = false;

        for (int i = 0; i < CheckList.size(); i++)
        {
            NPCChecks *check = CheckList[i];
            std::vector<std::string> param = check->Params.ToList();

            unsigned int tempUint;
            int tempInt;
            int tempInt2;
            Map *map;
            switch (check->Type)
            {
                case CheckType::CheckDay:
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                    auto day = DateTime::Now.DayOfWeek.ToString().ToUpper();
                    auto dayToCheck = StringHelper::toUpper(param[0]);

                    failed = day != dayToCheck;
                    break;

                }
                case CheckType::CheckHour:
                {
                    if (!unsigned int::TryParse(param[0], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    auto hour = DateTime::Now.Hour;
                    auto hourToCheck = tempUint;

                    failed = hour != hourToCheck;
                    break;

                }
                case CheckType::CheckMinute:
                {
                    if (!unsigned int::TryParse(param[0], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    auto minute = DateTime::Now.Minute;
                    auto minuteToCheck = tempUint;

                    failed = minute != minuteToCheck;
                    break;

                }
                case CheckType::CheckHum:
                    if (!int::TryParse(param[1], tempInt) || !int::TryParse(param[3], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[2], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = !Compare(param[0], map->Players.size()(), tempInt);

                    break;

                case CheckType::CheckMon:
                    if (!int::TryParse(param[1], tempInt) || !int::TryParse(param[3], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[2], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = !Compare(param[0], map->MonsterCount, tempInt);

                    break;

                case CheckType::CheckExactMon:
                    if (getEnvir()->GetMonsterInfo(param[0]) == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    if (!int::TryParse(param[2], tempInt) || !int::TryParse(param[4], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[3], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = (!Compare(param[1], getEnvir()->Objects.size()(([&] (std::any d)
                    {
                        return d->CurrentMap == map && d->Race == ObjectType::Monster && std::string::Equals(d->Name.Replace(" ", ""), param[0], StringComparison::OrdinalIgnoreCase) && !d::Dead;
                    })), tempInt));

                    break;

                case CheckType::Random:
                    if (!int::TryParse(param[0], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    failed = 0 != getEnvir()->Random->Next(0, tempInt);
                    break;
                case CheckType::CheckCalc:
                {
                    int left;
                    int right;

                    if (!int::TryParse(param[0], left) || !int::TryParse(param[2], right))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        failed = !Compare(param[1], left, right);
                    }
                    catch (const std::invalid_argument &e1)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[1], Key));
                        return true;
                    }
                    break;
                }
            }

            if (!failed)
            {
                continue;
            }

            Failed();
            return false;
        }

        Success();
        return true;

    }

    bool NPCSegment::Check(MonsterObject *monster)
    {
        auto failed = false;

        for (int i = 0; i < CheckList.size(); i++)
        {
            NPCChecks *check = CheckList[i];
            std::vector<std::string> param = check->Params.Select([&] (std::any t)
            {
                return FindVariable(monster, t);
            }).ToList();

            for (int j = 0; j < param.size(); j++)
            {
                auto parts = param[j].Split(std::vector<char> {' '}, StringSplitOptions::RemoveEmptyEntries);

                if (parts.empty())
                {
                    continue;
                }

                for (auto part : parts)
                {
                    param[j] = StringHelper::replace(param[j], part, ReplaceValue(monster, part));
                }
            }

            unsigned int tempUint;
            int tempInt;
            int tempInt2;
            Map *map;

            switch (check->Type)
            {
                case CheckType::Level:
                {
                        ushort level;
                        if (!unsigned short::TryParse(param[1], level))
                        {
                            failed = true;
                            break;
                        }

                        try
                        {
                            failed = !Compare(param[0], monster->getLevel(), level);
                        }
                        catch (const std::invalid_argument &e1)
                        {
                            getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                            return true;
                        }
                }
                    break;
                case CheckType::CheckDay:
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                    auto day = DateTime::Now.DayOfWeek.ToString().ToUpper();
                    auto dayToCheck = StringHelper::toUpper(param[0]);

                    failed = day != dayToCheck;
                    break;

                }
                case CheckType::CheckHour:
                {
                    if (!unsigned int::TryParse(param[0], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    auto hour = DateTime::Now.Hour;
                    auto hourToCheck = tempUint;

                    failed = hour != hourToCheck;
                    break;

                }
                case CheckType::CheckMinute:
                {
                    if (!unsigned int::TryParse(param[0], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    auto minute = DateTime::Now.Minute;
                    auto minuteToCheck = tempUint;

                    failed = minute != minuteToCheck;
                    break;

                }
                case CheckType::CheckRange:
                {
                    int x, y, range;
                    if (!int::TryParse(param[0], x) || !int::TryParse(param[1], y) || !int::TryParse(param[2], range))
                    {
                        failed = true;
                        break;
                    }

                    auto target = new Point();
                    target->X = x;
                    target->Y = y;

                    failed = !Functions::InRange(monster->getCurrentLocation(), target, range);

//C# TO C++ CONVERTER TODO TASK: A 'delete target' statement was not added since target was passed to a method or constructor. Handle memory management manually.
                    break;

//C# TO C++ CONVERTER TODO TASK: A 'delete target' statement was not added since target was passed to a method or constructor. Handle memory management manually.
                }
                case CheckType::CheckMap:
                    map = getEnvir()->GetMapByNameAndInstance(param[0]);

                    failed = monster->getCurrentMap() != map;
                    break;
                case CheckType::CheckHum:
                    if (!int::TryParse(param[1], tempInt) || !int::TryParse(param[3], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[2], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = !Compare(param[0], map->Players.size()(), tempInt);

                    break;

                case CheckType::CheckMon:
                    if (!int::TryParse(param[1], tempInt) || !int::TryParse(param[3], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[2], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = !Compare(param[0], map->MonsterCount, tempInt);

                    break;

                case CheckType::CheckExactMon:
                    if (getEnvir()->GetMonsterInfo(param[0]) == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    if (!int::TryParse(param[2], tempInt) || !int::TryParse(param[4], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[3], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = (!Compare(param[1], getEnvir()->Objects.size()(([&] (std::any d)
                    {
                        return d->CurrentMap == map && d->Race == ObjectType::Monster && std::string::Equals(d->Name.Replace(" ", ""), param[0], StringComparison::OrdinalIgnoreCase) && !d::Dead;
                    })), tempInt));

                    break;

                case CheckType::Random:
                    if (!int::TryParse(param[0], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    failed = 0 != getEnvir()->Random->Next(0, tempInt);
                    break;
                case CheckType::CheckCalc:
                {
                    int left;
                    int right;

                    if (!int::TryParse(param[0], left) || !int::TryParse(param[2], right))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        failed = !Compare(param[1], left, right);
                    }
                    catch (const std::invalid_argument &e2)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[1], Key));
                        return true;
                    }
                    break;
                }
            }

            if (!failed)
            {
                continue;
            }

            Failed(monster);
            return false;
        }

        Success(monster);
        return true;

    }

    bool NPCSegment::Check(PlayerObject *player)
    {
        auto failed = false;

        for (int i = 0; i < CheckList.size(); i++)
        {
            NPCChecks *check = CheckList[i];
            std::vector<std::string> param = check->Params.Select([&] (std::any t)
            {
                return FindVariable(player, t);
            }).ToList();

            for (int j = 0; j < param.size(); j++)
            {
                auto parts = param[j].Split(std::vector<char> {' '}, StringSplitOptions::RemoveEmptyEntries);

                if (parts.empty())
                {
                    continue;
                }

                for (auto part : parts)
                {
                    param[j] = StringHelper::replace(param[j], part, ReplaceValue(player, part));
                }
            }

            unsigned int tempUint;
            int tempInt;
            int tempInt2;

            switch (check->Type)
            {
                case CheckType::Level:
                {
                        ushort level;
                        if (!unsigned short::TryParse(param[1], level))
                        {
                            failed = true;
                            break;
                        }

                        try
                        {
                            failed = !Compare(param[0], player->getLevel(), level);
                        }
                        catch (const std::invalid_argument &e1)
                        {
                            getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                            return true;
                        }
                }
                    break;

                case CheckType::CheckGold:
                    if (!unsigned int::TryParse(param[1], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        failed = !Compare(param[0], player->Account->Gold, tempUint);
                    }
                    catch (const std::invalid_argument &e2)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
                case CheckType::CheckGuildGold:
                    if (!unsigned int::TryParse(param[1], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        failed = !Compare(param[0], player->MyGuild->Gold, tempUint);
                    }
                    catch (const std::invalid_argument &e3)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
                case CheckType::CheckCredit:
                    if (!unsigned int::TryParse(param[1], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        failed = !Compare(param[0], player->Account->Credit, tempUint);
                    }
                    catch (const std::invalid_argument &e4)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;

                case CheckType::CheckItem:
                {
                    unsigned short count;
                    unsigned short dura;

                    if (!unsigned short::TryParse(param[1], count))
                    {
                        failed = true;
                        break;
                    }

                    bool checkDura = unsigned short::TryParse(param[2], dura);

                    auto info = getEnvir()->GetItemInfo(param[0]);

                    for (auto item : *player->Info->Inventory.Where([&] (std::any item)
                    {
                        return item != nullptr && item->Info == info;
                    }))
                    {
                        if (checkDura)
                        {
                            if (item::CurrentDura < (dura * 1000))
                            {
                                continue;
                            }
                        }

                        if (count > item->Count)
                        {
                            count -= item->Count;
                            continue;
                        }

                        if (count > item->Count)
                        {
                            continue;
                        }
                        count = 0;
                        break;
                    }
                    if (count > 0)
                    {
                        failed = true;
                    }
                    break;

                }
                case CheckType::CheckGender:
                {
                    MirGender gender;

                    if (!MirGender::TryParse(param[0], false, gender))
                    {
                        failed = true;
                        break;
                    }

                    failed = player->getGender() != gender;
                    break;

                }
                case CheckType::CheckClass:
                {
                    MirClass mirClass;

                    if (!MirClass::TryParse(param[0], true, mirClass))
                    {
                        failed = true;
                        break;
                    }

                    failed = player->getClass() != mirClass;
                    break;

                }
                case CheckType::CheckDay:
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                    auto day = DateTime::Now.DayOfWeek.ToString().ToUpper();
                    auto dayToCheck = StringHelper::toUpper(param[0]);

                    failed = day != dayToCheck;
                    break;

                }
                case CheckType::CheckHour:
                {
                    if (!unsigned int::TryParse(param[0], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    auto hour = DateTime::Now.Hour;
                    auto hourToCheck = tempUint;

                    failed = hour != hourToCheck;
                    break;

                }
                case CheckType::CheckMinute:
                {
                    if (!unsigned int::TryParse(param[0], tempUint))
                    {
                        failed = true;
                        break;
                    }

                    auto minute = DateTime::Now.Minute;
                    auto minuteToCheck = tempUint;

                    failed = minute != minuteToCheck;
                    break;

                }
                case CheckType::CheckNameList:
                {
                    if (!FileSystem::fileExists(param[0]))
                    {
                        failed = true;
                        break;
                    }

                    auto read = File::ReadAllLines(param[0]);
                    failed = !std::find(read.begin(), read.end(), player->getName()) != read.end();
                    break;

                }
                case CheckType::CheckGuildNameList:
                    if (!FileSystem::fileExists(param[0]))
                    {
                        failed = true;
                        break;
                    }

                    read = File::ReadAllLines(param[0]);
                    failed = player->MyGuild == nullptr || !read->Contains(player->MyGuild->Name);
                    break;

                case CheckType::IsAdmin:
                    failed = !player->IsGM;
                    break;

                case CheckType::CheckPkPoint:
                    if (!int::TryParse(param[1], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        failed = !Compare(param[0], player->getPKPoints(), tempInt);
                    }
                    catch (const std::invalid_argument &e5)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;

                case CheckType::CheckRange:
                {
                    int x, y, range;
                    if (!int::TryParse(param[0], x) || !int::TryParse(param[1], y) || !int::TryParse(param[2], range))
                    {
                        failed = true;
                        break;
                    }

                    auto target = new Point();
                    target->X = x;
                    target->Y = y;

                    failed = !Functions::InRange(player->getCurrentLocation(), target, range);

//C# TO C++ CONVERTER TODO TASK: A 'delete target' statement was not added since target was passed to a method or constructor. Handle memory management manually.
                    break;

//C# TO C++ CONVERTER TODO TASK: A 'delete target' statement was not added since target was passed to a method or constructor. Handle memory management manually.
                }
                case CheckType::CheckMap:
                {
                    Map *map = getEnvir()->GetMapByNameAndInstance(param[0]);

                    failed = player->getCurrentMap() != map;
                    break;

                }
                case CheckType::Check:
                {
                    unsigned int onCheck;

                    if (!unsigned int::TryParse(param[0], tempUint) || !unsigned int::TryParse(param[1], onCheck) || tempUint > Globals::FlagIndexCount)
                    {
                        failed = true;
                        break;
                    }

                    bool tempBool = static_cast<bool>(onCheck);

                    bool flag = player->Info->Flags[tempUint];

                    failed = flag != tempBool;
                    break;

                }
                case CheckType::CheckHum:
                    if (!int::TryParse(param[1], tempInt) || !int::TryParse(param[3], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[2], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = !Compare(param[0], map::Players->Count(), tempInt);

                    break;

                case CheckType::CheckMon:
                    if (!int::TryParse(param[1], tempInt) || !int::TryParse(param[3], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[2], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = !Compare(param[0], map::MonsterCount, tempInt);

                    break;

                case CheckType::CheckExactMon:
                    if (getEnvir()->GetMonsterInfo(param[0]) == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    if (!int::TryParse(param[2], tempInt) || !int::TryParse(param[4], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[3], tempInt2);
                    if (map == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = (!Compare(param[1], getEnvir()->Objects.size()(([&] (std::any d)
                    {
                        return d->CurrentMap == map && d->Race == ObjectType::Monster && std::string::Equals(d->Name.Replace(" ", ""), param[0], StringComparison::OrdinalIgnoreCase) && !d::Dead;
                    })), tempInt));

                    break;

                case CheckType::Random:
                    if (!int::TryParse(param[0], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    failed = 0 != getEnvir()->Random->Next(0, tempInt);
                    break;

                case CheckType::Groupleader:
                    failed = (player->GroupMembers.empty() || player->GroupMembers[0] != player);
                    break;

                case CheckType::GroupCount:
                    if (!int::TryParse(param[1], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    failed = (player->GroupMembers.empty() || !Compare(param[0], player->GroupMembers.size(), tempInt));
                    break;
                case CheckType::GroupCheckNearby:
                    target = new Point(-1,-1);
                    for (int j = 0; j < player->getCurrentMap()->NPCs.size(); j++)
                    {
                        NPCObject *ob = player->getCurrentMap()->NPCs[j];
                        if (ob->ObjectID != player->NPCObjectID)
                        {
                            continue;
                        }
                        target = ob->getCurrentLocation();
                        break;
                    }
                    if (target->X == -1)
                    {
                        failed = true;
                        break;
                    }
                    if (player->GroupMembers.empty())
                    {
                        failed = true;
                    }
                    else
                    {
                        for (int j = 0; j < player->GroupMembers.size(); j++)
                        {
                            if (player->GroupMembers[j] == nullptr)
                            {
                                continue;
                            }
                            failed |= !Functions::InRange(player->GroupMembers[j]->getCurrentLocation(), target, 9);
                            if (failed)
                            {
                                break;
                            }
                        }
                    }
                    break;

                case CheckType::PetCount:
                    if (!int::TryParse(param[1], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    failed = !Compare(param[0], player->Pets.size()(), tempInt);
                    break;

                case CheckType::PetLevel:
                    if (!int::TryParse(param[1], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    for (int p = 0; p < player->Pets.size()(); p++)
                    {
                        failed = !Compare(param[0], player->Pets[p]->PetLevel, tempInt);
                    }
                    break;

                case CheckType::CheckCalc:
                {
                    int left;
                    int right;

                    try
                    {
                        if (!int::TryParse(param[0], left) || !int::TryParse(param[2], right))
                        {
                            failed = !Compare(param[1], param[0], param[2]);
                        }
                        else
                        {
                            failed = !Compare(param[1], left, right);
                        }
                    }
                    catch (const std::invalid_argument &e6)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[1], Key));
                        return true;
                    }
                    break;
                }
                case CheckType::InGuild:
                    if (param[0].length() > 0)
                    {
                        failed = player->MyGuild == nullptr || player->MyGuild->Name != param[0];
                        break;
                    }

                    failed = player->MyGuild == nullptr;
                    break;

                case CheckType::CheckQuest:
                {
                    if (!int::TryParse(param[0], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    std::string tempString = StringHelper::toUpper(param[1]);

                    if (tempString == "ACTIVE")
                    {
                        failed = !player->getCurrentQuests().Any([&] (std::any e)
                        {
                            return e->Index == tempInt;
                        });
                    }
                    else //COMPLETE
                    {
                        failed = !std::find(player->CompletedQuests.begin(), player->CompletedQuests.end(), tempInt) != player->CompletedQuests.end();
                    }
                    break;
                }
                case CheckType::CheckRelationship:
                    if (player->Info->Married == 0)
                    {
                        failed = true;
                    }
                    break;
                case CheckType::CheckWeddingRing:
                    failed = !player->CheckMakeWeddingRing();
                    break;
                case CheckType::CheckPet:
                {

                    bool petMatch = false;
                    for (int c = player->Pets.size() - 1; c >= 0; c--)
                    {
//C# TO C++ CONVERTER TODO TASK: The following System.String compare method is not converted:
                        if (std::string::Compare(player->Pets[c]->Info->Name, param[0], true) != 0)
                        {
                            continue;
                        }

                        petMatch = true;
                    }

                    failed = !petMatch;
                    break;

                }
                case CheckType::HasBagSpace:
                {
                    if (!int::TryParse(param[1], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    int slotCount = 0;

                    for (int k = 0; k < player->Info->Inventory.size(); k++)
                    {
                        if (player->Info->Inventory[k] == nullptr)
                        {
                            slotCount++;
                        }
                    }

                    failed = !Compare(param[0], slotCount, tempInt);
                    break;
                }
                case CheckType::IsNewHuman:
                    failed = player->Info->AccountInfo->Characters.size() > 1;
                    break;

                case CheckType::CheckConquest:
                    if (!int::TryParse(param[0], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        ConquestObject *Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (Conquest == nullptr)
                        {
                            failed = true;
                            break;
                        }
                        failed = Conquest->getWarIsOn();
                    }
                    catch (const std::invalid_argument &e7)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
                case CheckType::AffordGuard:
                    if (!int::TryParse(param[0], tempInt) || !int::TryParse(param[1], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        ConquestObject *Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (Conquest == nullptr)
                        {
                            failed = true;
                            break;
                        }

                        ConquestArcherObject *Archer = Conquest->ArcherList.FirstOrDefault([&] (std::any g)
                        {
                            return g::Info->Index == tempInt2;
                        });
                        if (Archer == nullptr || Archer->GetRepairCost() == 0)
                        {
                            failed = true;
                            break;
                        }
                        if (player->MyGuild != nullptr)
                        {
                            failed = (player->MyGuild->Gold < Archer->GetRepairCost());
                        }
                        else
                        {
                            failed = true;
                        }
                    }
                    catch (const std::invalid_argument &e8)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
                case CheckType::AffordGate:
                    if (!int::TryParse(param[0], tempInt) || !int::TryParse(param[1], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        ConquestObject *Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (Conquest == nullptr)
                        {
                            failed = true;
                            break;
                        }

                        ConquestGateObject *Gate = Conquest->GateList.FirstOrDefault([&] (std::any f)
                        {
                            return f::Info->Index == tempInt2;
                        });
                        if (Gate == nullptr || Gate->GetRepairCost() == 0)
                        {
                            failed = true;
                            break;
                        }
                        if (player->MyGuild != nullptr)
                        {
                            failed = (player->MyGuild->Gold < Gate->GetRepairCost());
                        }
                        else
                        {
                            failed = true;
                        }
                    }
                    catch (const std::invalid_argument &e9)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
                case CheckType::AffordWall:
                    if (!int::TryParse(param[0], tempInt) || !int::TryParse(param[1], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        ConquestObject *Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (Conquest == nullptr)
                        {
                            failed = true;
                            break;
                        }

                        ConquestWallObject *Wall = Conquest->WallList.FirstOrDefault([&] (std::any h)
                        {
                            return h::Info->Index == tempInt2;
                        });
                        if (Wall == nullptr || Wall->GetRepairCost() == 0)
                        {
                            failed = true;
                            break;
                        }
                        if (player->MyGuild != nullptr)
                        {
                            failed = (player->MyGuild->Gold < Wall->GetRepairCost());
                        }
                        else
                        {
                            failed = true;
                        }
                    }
                    catch (const std::invalid_argument &e10)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
                case CheckType::AffordSiege:
                    if (!int::TryParse(param[0], tempInt) || !int::TryParse(param[1], tempInt2))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        ConquestObject *Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (Conquest == nullptr)
                        {
                            failed = true;
                            break;
                        }

                        ConquestGateObject *Gate = Conquest->GateList.FirstOrDefault([&] (std::any f)
                        {
                            return f::Info->Index == tempInt2;
                        });
                        if (Gate == nullptr || Gate->GetRepairCost() == 0)
                        {
                            failed = true;
                            break;
                        }
                        if (player->MyGuild != nullptr)
                        {
                            failed = (player->MyGuild->Gold < Gate->GetRepairCost());
                        }
                        else
                        {
                            failed = true;
                        }
                    }
                    catch (const std::invalid_argument &e11)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
                case CheckType::CheckPermission:
                {
                    GuildRankOptions guildPermissions;
                    if (!Enum::TryParse(param[0], true, guildPermissions))
                    {
                        failed = true;
                        break;
                    }

                    if (player->MyGuild == nullptr)
                    {
                        failed = true;
                        break;
                    }

                    failed = !(player->MyGuildRank->Options::HasFlag(guildPermissions));

                    break;
                }
                case CheckType::ConquestAvailable:
                    if (!int::TryParse(param[0], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        ConquestObject *Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (Conquest == nullptr)
                        {
                            failed = true;
                            break;
                        }

                        if (player->MyGuild != nullptr)
                        {
                            failed = (Conquest->AttackerID != -1);
                        }
                        else
                        {
                            failed = true;
                        }
                    }
                    catch (const std::invalid_argument &e12)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
                case CheckType::ConquestOwner:
                    if (!int::TryParse(param[0], tempInt))
                    {
                        failed = true;
                        break;
                    }

                    try
                    {
                        ConquestObject *Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (Conquest == nullptr)
                        {
                            failed = true;
                            break;
                        }

                        if (player->MyGuild != nullptr && player->MyGuild->Guildindex == Conquest->Owner)
                        {
                            failed = false;
                        }
                        else
                        {
                            failed = true;
                        }
                    }
                    catch (const std::invalid_argument &e13)
                    {
                        getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[0], Key));
                        return true;
                    }
                    break;
            }

            if (!failed)
            {
                continue;
            }

            Failed(player);
            return false;
        }

        Success(player);
        return true;

    }

    void NPCSegment::Act(std::vector<NPCActions*> &acts)
    {
        for (auto i = 0; i < acts.size(); i++)
        {
            std::string tempString = "";
            int tempInt;
            unsigned char tempByte;
            Packet *p;

            MonsterInfo *monInfo;

            NPCActions *act = acts[i];
            std::vector<std::string> param = act->Params.ToList();
            Map *map;
            ChatType chatType;
            switch (act->Type)
            {
                case ActionType::ClearNameList:
                    tempString = param[0];
                    File::WriteAllLines(tempString, std::vector<std::string> ());
                    break;

                case ActionType::GlobalMessage:
                    if (!Enum::TryParse(param[1], true, chatType))
                    {
                        return;
                    }

                    p = new S::Chat();
                    p->Message = param[0];
                    p->Type = chatType;
                    getEnvir()->Broadcast(p);

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                    break;

                case ActionType::Break:
                    Page->BreakFromSegments = true;
                    break;

                case ActionType::Param1:
                    if (!int::TryParse(param[1], tempInt))
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    Param1 = param[0];
                    Param1Instance = tempInt;

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                    break;

                case ActionType::Param2:
                    if (!int::TryParse(param[0], tempInt))
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    Param2 = tempInt;

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                    break;

                case ActionType::Param3:
                    if (!int::TryParse(param[0], tempInt))
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    Param3 = tempInt;

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                    break;

                case ActionType::Mongen:
                    if (Param1 == "" || Param2 == 0 || Param3 == 0)
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }
                    if (!unsigned char::TryParse(param[1], tempByte))
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(Param1, Param1Instance);
                    if (map == nullptr)
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    monInfo = getEnvir()->GetMonsterInfo(param[0]);
                    if (monInfo == nullptr)
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    for (int j = 0; j < tempByte; j++)
                    {
                        MonsterObject *monster = MonsterObject::GetMonster(monInfo);
                        if (monster == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        monster->setDirection((MirDirection)0);
                        monster->ActionTime = getEnvir()->getTime() + 1000;
                        Point tempVar(Param2, Param3);
                        monster->Spawn(map, &tempVar);
                    }

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                    break;

                case ActionType::MonClear:
                    if (!int::TryParse(param[1], tempInt))
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    map = getEnvir()->GetMapByNameAndInstance(param[0], tempInt);
                    if (map == nullptr)
                    {
//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                        return;
                    }

                    for (auto cell : *map->Cells)
                    {
                        if (cell.empty() || cell.Objects == nullptr)
                        {
                            continue;
                        }

                        for (int j = 0; j < cell.Objects->Count(); j++)
                        {
                            MapObject *ob = cell.Objects[j];

                            if (ob->getRace() != ObjectType::Monster)
                            {
                                continue;
                            }
                            if (ob->Dead)
                            {
                                continue;
                            }
                            ob->Die();
                        }
                    }

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                    break;
            }

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
        }
    }

    void NPCSegment::Act(std::vector<NPCActions*> &acts, PlayerObject *player)
    {
        MailInfo *mailInfo = nullptr;

        for (auto i = 0; i < acts.size(); i++)
        {
            NPCActions *act = acts[i];
            std::vector<std::string> param = act->Params.Select([&] (std::any t)
            {
                return FindVariable(player, t);
            }).ToList();

            for (int j = 0; j < param.size(); j++)
            {
                auto parts = param[j].Split(std::vector<char> {' '}, StringSplitOptions::RemoveEmptyEntries);

                if (parts.empty())
                {
                    continue;
                }

                for (auto part : parts)
                {
                    param[j] = StringHelper::replace(param[j], part, ReplaceValue(player, part));
                }

                param[j] = StringHelper::replace(param[j], "%INPUTSTR", player->NPCInputStr);
            }

            switch (act->Type)
            {
                case ActionType::Move:
                {
                        Map *map = getEnvir()->GetMapByNameAndInstance(param[0]);
                        if (map == nullptr)
                        {
                            return;
                        }

                        int x;
                        if (!int::TryParse(param[1], x))
                        {
                            return;
                        }
                        int y;
                        if (!int::TryParse(param[2], y))
                        {
                            return;
                        }

                        auto coords = new Point(x, y);

                        if (coords->X > 0 && coords->Y > 0)
                        {
                            player->Teleport(map, coords);
                        }
                        else
                        {
                            player->TeleportRandom(200, 0, map);
                        }

//C# TO C++ CONVERTER TODO TASK: A 'delete coords' statement was not added since coords was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::InstanceMove:
                {
                        int instanceId;
                        if (!int::TryParse(param[1], instanceId))
                        {
                            return;
                        }
                        int x;
                        if (!int::TryParse(param[2], x))
                        {
                            return;
                        }
                        int y;
                        if (!int::TryParse(param[3], y))
                        {
                            return;
                        }

                        auto map = getEnvir()->GetMapByNameAndInstance(param[0], instanceId);
                        if (map == nullptr)
                        {
                            return;
                        }
                        Point tempVar(x, y);
                        player->Teleport(map, &tempVar);
                }
                    break;

                case ActionType::GiveGold:
                {
                        uint gold;
                        if (!unsigned int::TryParse(param[0], gold))
                        {
                            return;
                        }

                        if (gold + player->Account->Gold >= std::numeric_limits<unsigned int>::max())
                        {
                            gold = std::numeric_limits<unsigned int>::max() - player->Account->Gold;
                        }

                        player->GainGold(gold);
                }
                    break;

                case ActionType::TakeGold:
                {
                        uint gold;
                        if (!unsigned int::TryParse(param[0], gold))
                        {
                            return;
                        }

                        if (gold >= player->Account->Gold)
                        {
                            gold = player->Account->Gold;
                        }

                        player->Account->Gold -= gold;
                        S::LoseGold *tempVar2 = new S::LoseGold();
                        tempVar2->Gold = gold;
                        player->Enqueue(tempVar2);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
                }
                    break;
                case ActionType::GiveGuildGold:
                {
                        uint gold;
                        if (!unsigned int::TryParse(param[0], gold))
                        {
                            return;
                        }

                        if (gold + player->MyGuild->Gold >= std::numeric_limits<unsigned int>::max())
                        {
                            gold = std::numeric_limits<unsigned int>::max() - player->MyGuild->Gold;
                        }

                        player->MyGuild->Gold += gold;
                        S::GuildStorageGoldChange *tempVar3 = new S::GuildStorageGoldChange();
                        tempVar3->Type = 3;
                        tempVar3->Amount = gold;
                        player->MyGuild->SendServerPacket(tempVar3);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar3' statement was not added since tempVar3 was passed to a method or constructor. Handle memory management manually.
                }
                    break;
                case ActionType::TakeGuildGold:
                {
                        uint gold;
                        if (!unsigned int::TryParse(param[0], gold))
                        {
                            return;
                        }

                        if (gold >= player->MyGuild->Gold)
                        {
                            gold = player->MyGuild->Gold;
                        }

                        player->MyGuild->Gold -= gold;
                        S::GuildStorageGoldChange *tempVar4 = new S::GuildStorageGoldChange();
                        tempVar4->Type = 2;
                        tempVar4->Amount = gold;
                        player->MyGuild->SendServerPacket(tempVar4);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar4' statement was not added since tempVar4 was passed to a method or constructor. Handle memory management manually.
                }
                    break;
                case ActionType::GiveCredit:
                {
                        uint credit;
                        if (!unsigned int::TryParse(param[0], credit))
                        {
                            return;
                        }

                        if (credit + player->Account->Credit >= std::numeric_limits<unsigned int>::max())
                        {
                            credit = std::numeric_limits<unsigned int>::max() - player->Account->Credit;
                        }

                        player->GainCredit(credit);
                }
                    break;

                case ActionType::TakeCredit:
                {
                        uint credit;
                        if (!unsigned int::TryParse(param[0], credit))
                        {
                            return;
                        }

                        if (credit >= player->Account->Credit)
                        {
                            credit = player->Account->Credit;
                        }

                        player->Account->Credit -= credit;
                        S::LoseCredit *tempVar5 = new S::LoseCredit();
                        tempVar5->Credit = credit;
                        player->Enqueue(tempVar5);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar5' statement was not added since tempVar5 was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::GivePearls:
                {
                        uint pearls;
                        if (!unsigned int::TryParse(param[0], pearls))
                        {
                            return;
                        }

                        if (pearls + player->Info->PearlCount >= std::numeric_limits<int>::max())
                        {
                            pearls = static_cast<unsigned int>(std::numeric_limits<int>::max() - player->Info->PearlCount);
                        }

                        player->IntelligentCreatureGainPearls(static_cast<int>(pearls));
                }
                    break;

                case ActionType::TakePearls:
                {
                        uint pearls;
                        if (!unsigned int::TryParse(param[0], pearls))
                        {
                            return;
                        }

                        if (pearls >= player->Info->PearlCount)
                        {
                            pearls = static_cast<unsigned int>(player->Info->PearlCount);
                        }

                        player->IntelligentCreatureLosePearls(static_cast<int>(pearls));
                }
                    break;

                case ActionType::GiveItem:
                {
                        ushort count;
                        if (param.size() < 2 || !unsigned short::TryParse(param[1], count))
                        {
                            count = 1;
                        }

                        auto info = getEnvir()->GetItemInfo(param[0]);

                        if (info == nullptr)
                        {
                            getMessageQueue()->Enqueue(StringHelper::formatSimple("Failed to get ItemInfo: {0}, Page: {1}", param[0], Key));
                            break;
                        }

                        while (count > 0)
                        {
                            UserItem *item = getEnvir()->CreateFreshItem(info);

                            if (item == nullptr)
                            {
                                getMessageQueue()->Enqueue(StringHelper::formatSimple("Failed to create UserItem: {0}, Page: {1}", param[0], Key));
                                return;
                            }

                            if (item->Info->StackSize > count)
                            {
                                item->Count = count;
                                count = 0;
                            }
                            else
                            {
                                count -= item->Info->StackSize;
                                item->Count = item->Info->StackSize;
                            }

                            if (player->CanGainItem(item, false))
                            {
                                player->GainItem(item);
                            }
                        }
                }
                    break;

                case ActionType::TakeItem:
                {
                        ushort count;
                        if (param.size() < 2 || !unsigned short::TryParse(param[1], count))
                        {
                            count = 1;
                        }
                        auto info = getEnvir()->GetItemInfo(param[0]);

                        unsigned short dura;
                        bool checkDura = unsigned short::TryParse(param[2], dura);

                        if (info == nullptr)
                        {
                            getMessageQueue()->Enqueue(StringHelper::formatSimple("Failed to get ItemInfo: {0}, Page: {1}", param[0], Key));
                            break;
                        }

                        for (int j = 0; j < player->Info->Inventory.size(); j++)
                        {
                            UserItem *item = player->Info->Inventory[j];
                            if (item == nullptr)
                            {
                                continue;
                            }
                            if (item->Info != info)
                            {
                                continue;
                            }

                            if (checkDura)
                            {
                                if (item->CurrentDura < (dura * 1000))
                                {
                                    continue;
                                }
                            }

                            if (count > item->Count)
                            {
                                S::DeleteItem *tempVar6 = new S::DeleteItem();
                                tempVar6->UniqueID = item->UniqueID;
                                tempVar6->Count = item->Count;
                                player->Enqueue(tempVar6);
                                player->Info->Inventory[j] = nullptr;

                                count -= item->Count;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar6' statement was not added since tempVar6 was passed to a method or constructor. Handle memory management manually.
                                continue;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar6' statement was not added since tempVar6 was passed to a method or constructor. Handle memory management manually.
                            }

                            S::DeleteItem *tempVar7 = new S::DeleteItem();
                            tempVar7->UniqueID = item->UniqueID;
                            tempVar7->Count = count;
                            player->Enqueue(tempVar7);
                            if (count == item->Count)
                            {
                                player->Info->Inventory[j] = nullptr;
                            }
                            else
                            {
                                item->Count -= count;
                            }

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar7' statement was not added since tempVar7 was passed to a method or constructor. Handle memory management manually.
                            break;
                        }
                        player->RefreshStats();
                }
                    break;

                case ActionType::GiveExp:
                {
                        unsigned int tempUint;
                        if (!unsigned int::TryParse(param[0], tempUint))
                        {
                            return;
                        }
                        player->GainExp(tempUint);
                }
                    break;

                case ActionType::GivePet:
                {
                        unsigned char petcount = 0;
                        unsigned char petlevel = 0;

                        auto monInfo = getEnvir()->GetMonsterInfo(param[0]);
                        if (monInfo == nullptr)
                        {
                            return;
                        }

                        if (param.size() > 1)
                        {
                            petcount = unsigned char::TryParse(param[1], petcount) ? std::min(static_cast<unsigned char>(5), petcount) : static_cast<unsigned char>(1);
                        }

                        if (param.size() > 2)
                        {
                            petlevel = unsigned char::TryParse(param[2], petlevel) ? std::min(static_cast<unsigned char>(7), petlevel) : static_cast<unsigned char>(0);
                        }

                        for (int j = 0; j < petcount; j++)
                        {
                            MonsterObject *monster = MonsterObject::GetMonster(monInfo);
                            if (monster == nullptr)
                            {
                                return;
                            }
                            monster->PetLevel = petlevel;
                            monster->Master = player;
                            monster->MaxPetLevel = 7;
                            monster->setDirection(player->getDirection());
                            monster->ActionTime = getEnvir()->getTime() + 1000;
                            monster->Spawn(player->getCurrentMap(), player->getCurrentLocation());
                            player->Pets.push_back(monster);
                        }
                }
                    break;

                case ActionType::RemovePet:
                {
                        for (int c = player->Pets.size() - 1; c >= 0; c--)
                        {
//C# TO C++ CONVERTER TODO TASK: The following System.String compare method is not converted:
                            if (std::string::Compare(player->Pets[c]->Info->Name, param[0], true) != 0)
                            {
                                continue;
                            }

                            player->Pets[c]->Die();
                        }
                }
                    break;

                case ActionType::ClearPets:
                {
                        for (int c = player->Pets.size() - 1; c >= 0; c--)
                        {
                            player->Pets[c]->Die();
                        }
                }
                    break;

                case ActionType::AddNameList:
                {
                        auto tempString = param[0];
                        if (File::ReadAllLines(tempString).All([&] (std::any t)
                        {
                            return player->getName() != t;
                        }))
                        {
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (var line = File.AppendText(tempString))
                            {
                                auto line = File::AppendText(tempString);
                                line.WriteLine(player->getName());
                            }
                        }
                }
                    break;


                case ActionType::AddGuildNameList:
                {
                        auto tempString = param[0];
                        if (player->MyGuild == nullptr)
                        {
                            break;
                        }
                        if (File::ReadAllLines(tempString).All([&] (std::any t)
                        {
                            return player->MyGuild->Name != t;
                        }))
                        {
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (var line = File.AppendText(tempString))
                            {
                                auto line = File::AppendText(tempString);
                                line.WriteLine(player->MyGuild->Name);
                            }
                        }
                }
                    break;
                case ActionType::DelNameList:
                {
                        auto tempString = param[0];
                        File::WriteAllLines(tempString, File::ReadLines(tempString).Where([&] (std::any l)
                        {
                            return l != player->getName();
                        }).ToList());
                }
                    break;

                case ActionType::DelGuildNameList:
                {
                        if (player->MyGuild == nullptr)
                        {
                            break;
                        }
                        auto tempString = param[0];
                        File::WriteAllLines(tempString, File::ReadLines(tempString).Where([&] (std::any l)
                        {
                            return l != player->MyGuild->Name;
                        }).ToList());
                }
                    break;
                case ActionType::ClearNameList:
                {
                        auto tempString = param[0];
                        File::WriteAllLines(tempString, std::vector<std::string> ());
                }
                    break;
                case ActionType::ClearGuildNameList:
                {
                        if (player->MyGuild == nullptr)
                        {
                            break;
                        }
                        auto tempString = param[0];
                        File::WriteAllLines(tempString, std::vector<std::string> ());
                }
                    break;

                case ActionType::GiveHP:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }
                        player->ChangeHP(tempInt);
                }
                    break;

                case ActionType::GiveMP:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }
                        player->ChangeMP(tempInt);
                }
                    break;

                case ActionType::ChangeLevel:
                {
                        ushort tempuShort;
                        if (!unsigned short::TryParse(param[0], tempuShort))
                        {
                            return;
                        }
                        tempuShort = std::min(std::numeric_limits<unsigned short>::max(), tempuShort);

                        player->setLevel(tempuShort);
                        player->setExperience(0);
                        player->LevelUp();
                }
                    break;

                case ActionType::SetPkPoint:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }
                        player->setPKPoints(tempInt);
                }
                    break;

                case ActionType::ReducePkPoint:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }

                        player->setPKPoints(player->getPKPoints() - tempInt);
                        if (player->getPKPoints() < 0)
                        {
                            player->setPKPoints(0);
                        }
                }
                    break;

                case ActionType::IncreasePkPoint:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }
                        player->setPKPoints(player->getPKPoints() + tempInt);
                }
                    break;

                case ActionType::ChangeGender:
                {
                        switch (player->Info->Gender)
                        {
                            case MirGender::Male:
                                player->Info->Gender = MirGender::Female;
                                break;
                            case MirGender::Female:
                                player->Info->Gender = MirGender::Male;
                                break;
                        }
                }
                    break;

                case ActionType::ChangeHair:
                {
                        if (param.size() < 1)
                        {
                            player->Info->Hair = static_cast<unsigned char>(getEnvir()->Random->Next(0, 9));
                        }
                        else
                        {
                            byte tempByte;
                            unsigned char::TryParse(param[0], tempByte);

                            if (tempByte >= 0 && tempByte <= 9)
                            {
                                player->Info->Hair = tempByte;
                            }
                        }
                }
                    break;

                case ActionType::ChangeClass:
                {
                        MirClass mirClass;
                        if (!Enum::TryParse(param[0], true, mirClass))
                        {
                            return;
                        }

                        switch (mirClass)
                        {
                            case MirClass::Warrior:
                                player->Info->Class = MirClass::Warrior;
                                break;
                            case MirClass::Taoist:
                                player->Info->Class = MirClass::Taoist;
                                break;
                            case MirClass::Wizard:
                                player->Info->Class = MirClass::Wizard;
                                break;
                            case MirClass::Assassin:
                                player->Info->Class = MirClass::Assassin;
                                break;
                            case MirClass::Archer:
                                player->Info->Class = MirClass::Archer;
                                break;
                        }
                }
                    break;

                case ActionType::LocalMessage:
                {
                        ChatType chatType;
                        if (!Enum::TryParse(param[1], true, chatType))
                        {
                            return;
                        }
                        player->ReceiveChat(param[0], chatType);
                }
                    break;

                case ActionType::GlobalMessage:
                {
                        ChatType chatType;
                        if (!Enum::TryParse(param[1], true, chatType))
                        {
                            return;
                        }

                        auto p = new S::Chat();
                        p->Message = param[0];
                        p->Type = chatType;
                        getEnvir()->Broadcast(p);

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::GiveSkill:
                {
                        unsigned char spellLevel = 0;

                        Spell skill;
                        if (!Enum::TryParse(param[0], true, skill))
                        {
                            return;
                        }

                        if (player->Info->Magics.Any([&] (std::any e)
                        {
                            return e->Spell == skill;
                        }))
                        {
                            break;
                        }

                        if (param.size() > 1)
                        {
                            spellLevel = unsigned char::TryParse(param[1], spellLevel) ? std::min(static_cast<unsigned char>(3), spellLevel) : static_cast<unsigned char>(0);
                        }

                        auto magic = new UserMagic(skill);
                        magic->Level = spellLevel;

                        if (magic->Info == nullptr)
                        {
                            delete magic;
                            return;
                        }

                        player->Info->Magics.push_back(magic);
                        player->Enqueue(magic->GetInfo());

//C# TO C++ CONVERTER TODO TASK: A 'delete magic' statement was not added since magic was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::RemoveSkill:
                {
                        Spell skill;
                        if (!Enum::TryParse(param[0], true, skill))
                        {
                            return;
                        }

                        if (!player->Info->Magics.Any([&] (std::any e)
                        {
                            return e->Spell == skill;
                        }))
                        {
                            break;
                        }

                        for (auto j = player->Info->Magics.size() - 1; j >= 0; j--)
                        {
                            if (player->Info->Magics[j]->Spell != skill)
                            {
                                continue;
                            }

                            player->Info->Magics.erase(player->Info->Magics.begin() + j);
                            S::RemoveMagic *tempVar8 = new S::RemoveMagic();
                            tempVar8->PlaceId = j;
                            player->Enqueue(tempVar8);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar8' statement was not added since tempVar8 was passed to a method or constructor. Handle memory management manually.
                        }
                }
                    break;

                case ActionType::Goto:
                {
                        DelayedAction *action = new DelayedAction(DelayedType::NPC, -1, {player->NPCObjectID, "[" + param[0] + "]"});
                        player->ActionList.push_back(action);

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::Call:
                {
                        int scriptID;
                        if (!int::TryParse(param[0], scriptID))
                        {
                            return;
                        }

                        auto action = new DelayedAction(DelayedType::NPC, -1, {player->NPCObjectID, "[@MAIN]", scriptID});
                        player->ActionList.push_back(action);

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::Break:
                {
                        Page->BreakFromSegments = true;
                }
                    break;

                case ActionType::Set:
                {
                        int flagIndex;
                        unsigned int onCheck;
                        if (!int::TryParse(param[0], flagIndex))
                        {
                            return;
                        }
                        if (!unsigned int::TryParse(param[1], onCheck))
                        {
                            return;
                        }

                        if (flagIndex < 0 || flagIndex >= Globals::FlagIndexCount)
                        {
                            return;
                        }
                        auto flagIsOn = static_cast<bool>(onCheck);

                        player->Info->Flags[flagIndex] = flagIsOn;

                        for (int f = player->getCurrentMap()->NPCs.size() - 1; f >= 0; f--)
                        {
                            if (Functions::InRange(player->getCurrentMap()->NPCs[f]->getCurrentLocation(), player->getCurrentLocation(), Globals::DataRange))
                            {
                                player->getCurrentMap()->NPCs[f]->CheckVisible(player);
                            }
                        }

                        if (flagIsOn)
                        {
                            player->CheckNeedQuestFlag(flagIndex);
                        }
                }
                    break;

                case ActionType::Param1:
                {
                        int tempInt;
                        if (!int::TryParse(param[1], tempInt))
                        {
                            return;
                        }

                        Param1 = param[0];
                        Param1Instance = tempInt;
                }
                    break;

                case ActionType::Param2:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }

                        Param2 = tempInt;
                }
                    break;

                case ActionType::Param3:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }

                        Param3 = tempInt;
                }
                    break;

                case ActionType::Mongen:
                {
                        if (Param1 == "" || Param2 == 0 || Param3 == 0)
                        {
                            return;
                        }
                        byte tempByte;
                        if (!unsigned char::TryParse(param[1], tempByte))
                        {
                            return;
                        }

                        Map *map = getEnvir()->GetMapByNameAndInstance(Param1, Param1Instance);
                        if (map == nullptr)
                        {
                            return;
                        }

                        auto monInfo = getEnvir()->GetMonsterInfo(param[0]);
                        if (monInfo == nullptr)
                        {
                            return;
                        }

                        for (int j = 0; j < tempByte; j++)
                        {
                            MonsterObject *monster = MonsterObject::GetMonster(monInfo);
                            if (monster == nullptr)
                            {
                                return;
                            }
                            monster->setDirection((MirDirection)0);
                            monster->ActionTime = getEnvir()->getTime() + 1000;
                            Point tempVar9(Param2, Param3);
                            monster->Spawn(map, &tempVar9);
                        }
                }
                    break;

                case ActionType::TimeRecall:
                {
                        auto tempString = "";
                        long tempLong;
                        if (!long long::TryParse(param[0], tempLong))
                        {
                            return;
                        }

                        if (param[1].length() > 0)
                        {
                            tempString = "[" + param[1] + "]";
                        }

                        Map *tempMap = player->getCurrentMap();
                        Point *tempPoint = player->getCurrentLocation();

                        auto action = new DelayedAction(DelayedType::NPC, getEnvir()->getTime() + (tempLong * 1000), {player->NPCObjectID, tempString, tempMap, tempPoint});
                        player->ActionList.push_back(action);

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::TimeRecallGroup:
                {
                        auto tempString = "";
                        if (player->GroupMembers.empty())
                        {
                            return;
                        }
                        long tempLong;
                        if (!long long::TryParse(param[0], tempLong))
                        {
                            return;
                        }
                        if (param[1].length() > 0)
                        {
                            tempString = "[" + param[1] + "]";
                        }

                        for (int j = 0; j < player->GroupMembers.size()(); j++)
                        {
                            auto groupMember = player->GroupMembers[j];

                            auto action = new DelayedAction(DelayedType::NPC, getEnvir()->getTime() + (tempLong * 1000), {player->NPCObjectID, tempString, player->getCurrentMap(), player->getCurrentLocation()});
                            groupMember->ActionList.push_back(action);

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
                        }
                }
                    break;

                case ActionType::BreakTimeRecall:
                {
                        for (DelayedAction *ac : *player->ActionList.Where([&] (std::any u)
                        {
                            return u->Type == DelayedType::NPC;
                        }))
                        {
                            ac->FlaggedToRemove = true;
                        }
                }
                    break;

                case ActionType::DelayGoto:
                {
                        long tempLong;
                        if (!long long::TryParse(param[0], tempLong))
                        {
                            return;
                        }

                        auto action = new DelayedAction(DelayedType::NPC, getEnvir()->getTime() + (tempLong * 1000), {player->NPCObjectID, "[" + param[1] + "]"});
                        player->ActionList.push_back(action);

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::MonClear:
                {
                        int tempInt;
                        if (!int::TryParse(param[1], tempInt))
                        {
                            return;
                        }

                        auto map = getEnvir()->GetMapByNameAndInstance(param[0], tempInt);
                        if (map == nullptr)
                        {
                            return;
                        }

                        for (auto cell : *map->Cells)
                        {
                            if (cell.empty() || cell.Objects == nullptr)
                            {
                                continue;
                            }

                            for (int j = 0; j < cell.Objects->Count(); j++)
                            {
                                MapObject *ob = cell.Objects[j];

                                if (ob->getRace() != ObjectType::Monster)
                                {
                                    continue;
                                }
                                if (ob->Dead)
                                {
                                    continue;
                                }

//C# TO C++ CONVERTER TODO TASK: The following System.String compare method is not converted:
                                if (!(param[2]).empty() && std::string::Compare(param[2], (static_cast<MonsterObject*>(ob))->Info->Name, true) != 0)
                                {
                                    continue;
                                }

                                ob->Die();
                            }
                        }
                }
                    break;
                case ActionType::GroupRecall:
                {
                        if (player->GroupMembers.empty())
                        {
                            return;
                        }

                        for (int j = 0; j < player->GroupMembers.size()(); j++)
                        {
                            player->GroupMembers[j]->Teleport(player->getCurrentMap(), player->getCurrentLocation());
                        }
                }
                    break;

                case ActionType::GroupTeleport:
                {
                        if (player->GroupMembers.empty())
                        {
                            return;
                        }
                        int tempInt;
                        if (!int::TryParse(param[1], tempInt))
                        {
                            return;
                        }
                        int x;
                        if (!int::TryParse(param[2], x))
                        {
                            return;
                        }
                        int y;
                        if (!int::TryParse(param[3], y))
                        {
                            return;
                        }

                        auto map = getEnvir()->GetMapByNameAndInstance(param[0], tempInt);
                        if (map == nullptr)
                        {
                            return;
                        }

                        for (int j = 0; j < player->GroupMembers.size()(); j++)
                        {
                            if (x == 0 || y == 0)
                            {
                                player->GroupMembers[j]->TeleportRandom(200, 0, map);
                            }
                            else
                            {
                                Point tempVar10(x, y);
                                player->GroupMembers[j]->Teleport(map, &tempVar10);
                            }
                        }
                }
                    break;

                case ActionType::Mov:
                {
                        std::string value = param[0];
                        AddVariable(player, value, param[1]);
                }
                    break;

                case ActionType::Calc:
                {
                        int left;
                        int right;

                        bool resultLeft = int::TryParse(param[0], left);
                        bool resultRight = int::TryParse(param[2], right);

                        if (resultLeft && resultRight)
                        {
                            try
                            {
                                int result = Calculate(param[1], left, right);
                                AddVariable(player, StringHelper::replace(param[3], "-", ""), std::to_string(result));
                            }
                            catch (const std::invalid_argument &e1)
                            {
                                getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[1], Key));
                            }
                        }
                        else
                        {
                            AddVariable(player, StringHelper::replace(param[3], "-", ""), param[0] + param[2]);
                        }
                }
                    break;

                case ActionType::GiveBuff:
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
                        if (!Enum::IsDefined(typeof(BuffType), param[0]))
                        {
                            return;
                        }

                        int duration;
                        int::TryParse(param[1], duration);
                        bool infinite;
                        bool::TryParse(param[2], infinite);
                        bool visible;
                        bool::TryParse(param[3], visible);
                        bool stackable;
                        bool::TryParse(param[4], stackable);

//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
                        Stats tempVar11();
                        player->AddBuff(static_cast<BuffType>(std::any_cast<unsigned char>(Enum::Parse(typeof(BuffType), param[0], true))), player, Settings::Second * duration, &tempVar11, visible, infinite, stackable);
                }
                    break;

                case ActionType::RemoveBuff:
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
                        if (!Enum::IsDefined(typeof(BuffType), param[0]))
                        {
                            return;
                        }

//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
                        BuffType bType = static_cast<BuffType>(std::any_cast<unsigned char>(Enum::Parse(typeof(BuffType), param[0])));

                        player->RemoveBuff(bType);
                }
                    break;

                case ActionType::AddToGuild:
                {
                        if (player->MyGuild != nullptr)
                        {
                            return;
                        }

                        GuildObject *guild = getEnvir()->GetGuild(param[0]);

                        if (guild == nullptr)
                        {
                            return;
                        }

                        player->PendingGuildInvite = guild;
                        player->GuildInvite(true);
                }
                    break;

                case ActionType::RemoveFromGuild:
                {
                        if (player->MyGuild == nullptr)
                        {
                            return;
                        }

                        if (player->MyGuildRank == nullptr)
                        {
                            return;
                        }

                        player->MyGuild->DeleteMember(player, player->getName());
                }
                    break;

                case ActionType::RefreshEffects:
                {
                        player->SetLevelEffects();
                        auto p = new S::ObjectLevelEffects();
                        p->ObjectID = player->ObjectID;
                        p->LevelEffects = player->LevelEffects;
                        player->Enqueue(p);
                        player->Broadcast(p);

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::CanGainExp:
                {
                        bool tempBool;
                        bool::TryParse(param[0], tempBool);
                        player->CanGainExp = tempBool;
                }
                    break;

                case ActionType::ComposeMail:
                {
                        mailInfo = new MailInfo(player->Info->Index, false);
                        mailInfo->Sender = param[1];
                        mailInfo->Message = param[0];
                }
                    break;
                case ActionType::AddMailGold:
                {
                        if (mailInfo == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        uint tempUint;
                        unsigned int::TryParse(param[0], tempUint);

                        mailInfo->Gold += tempUint;
                }
                    break;

                case ActionType::AddMailItem:
                {
                        if (mailInfo == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        if (mailInfo->Items.size() > 5)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        ushort count;
                        if (param.size() < 2 || !unsigned short::TryParse(param[1], count))
                        {
                            count = 1;
                        }

                        auto info = getEnvir()->GetItemInfo(param[0]);

                        if (info == nullptr)
                        {
                            getMessageQueue()->Enqueue(StringHelper::formatSimple("Failed to get ItemInfo: {0}, Page: {1}", param[0], Key));
                            break;
                        }

                        while (count > 0 && mailInfo->Items.size() < 5)
                        {
                            UserItem *item = getEnvir()->CreateFreshItem(info);

                            if (item == nullptr)
                            {
                                getMessageQueue()->Enqueue(StringHelper::formatSimple("Failed to create UserItem: {0}, Page: {1}", param[0], Key));

//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                                return;
                            }

                            if (item->Info->StackSize > count)
                            {
                                item->Count = count;
                                count = 0;
                            }
                            else
                            {
                                count -= item->Info->StackSize;
                                item->Count = item->Info->StackSize;
                            }

                            mailInfo->Items.push_back(item);
                        }
                }
                    break;

                case ActionType::SendMail:
                {
                        if (mailInfo == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        mailInfo->Send();
                }
                    break;

                case ActionType::GroupGoto:
                {
                        if (player->GroupMembers.empty())
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        for (int j = 0; j < player->GroupMembers.size()(); j++)
                        {
                            auto action = new DelayedAction(DelayedType::NPC, getEnvir()->getTime(), {player->NPCObjectID, "[" + param[0] + "]"});
                            player->GroupMembers[j]->ActionList.push_back(action);

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
                        }
                }
                    break;

                case ActionType::EnterMap:
                {
                        if (player->NPCMoveMap == nullptr || player->NPCMoveCoord->IsEmpty)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        player->Teleport(player->NPCMoveMap, player->NPCMoveCoord, false);
                        player->NPCMoveMap = nullptr;
                        player->NPCMoveCoord = Point::Empty;
                }
                    break;

                case ActionType::MakeWeddingRing:
                {
                        player->MakeWeddingRing();
                }
                    break;

                case ActionType::ForceDivorce:
                {
                        player->NPCDivorce();
                }
                    break;

                case ActionType::LoadValue:
                {
                        std::string val = param[0];
                        std::string filePath = param[1];
                        std::string header = param[2];
                        std::string key = param[3];

                        InIReader *reader = new InIReader(filePath);
                        std::string loadedString = reader->ReadString(header, key, "");

                        if (loadedString == "")
                        {
                            delete reader;
                            break;
                        }
                        AddVariable(player, val, loadedString);

                        delete reader;
                }
                    break;

                case ActionType::SaveValue:
                {
                        std::string filePath = param[0];
                        std::string header = param[1];
                        std::string key = param[2];
                        std::string val = param[3];

                        InIReader *reader = new InIReader(filePath);
                        reader->Write(header, key, val);

                        delete reader;
                }
                    break;
                case ActionType::ConquestGuard:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (!int::TryParse(param[1], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        ConquestArcherObject *conquestArcher = conquest->ArcherList.FirstOrDefault([&] (std::any z)
                        {
                            return z->Index == tempInt;
                        });
                        if (conquestArcher == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (conquestArcher->ArcherMonster != nullptr)
                        {
                            if (!conquestArcher->ArcherMonster->Dead)
                            {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                                return;
                            }
                        }

                        if (player->MyGuild == nullptr || player->MyGuild->Gold < conquestArcher->GetRepairCost())
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        player->MyGuild->Gold -= conquestArcher->GetRepairCost();
                        S::GuildStorageGoldChange *tempVar12 = new S::GuildStorageGoldChange();
                        tempVar12->Type = 2;
                        tempVar12->Amount = conquestArcher->GetRepairCost();
                        player->MyGuild->SendServerPacket(tempVar12);

                        conquestArcher->Spawn(true);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar12' statement was not added since tempVar12 was passed to a method or constructor. Handle memory management manually.
                }
                    break;
                case ActionType::ConquestGate:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (!int::TryParse(param[1], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        ConquestGateObject *conquestGate = conquest->GateList.FirstOrDefault([&] (std::any z)
                        {
                            return z->Index == tempInt;
                        });
                        if (conquestGate == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (player->MyGuild == nullptr || player->MyGuild->Gold < conquestGate->GetRepairCost())
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        player->MyGuild->Gold -= static_cast<unsigned int>(conquestGate->GetRepairCost());
                        S::GuildStorageGoldChange *tempVar13 = new S::GuildStorageGoldChange();
                        tempVar13->Type = 2;
                        tempVar13->Amount = static_cast<unsigned int>(conquestGate->GetRepairCost());
                        player->MyGuild->SendServerPacket(tempVar13);

                        conquestGate->Repair();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar13' statement was not added since tempVar13 was passed to a method or constructor. Handle memory management manually.
                }
                    break;
                case ActionType::ConquestWall:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (!int::TryParse(param[1], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        ConquestWallObject *conquestWall = conquest->WallList.FirstOrDefault([&] (std::any z)
                        {
                            return z->Index == tempInt;
                        });

                        if (conquestWall == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        unsigned int repairCost = static_cast<unsigned int>(conquestWall->GetRepairCost());

                        if (player->MyGuild == nullptr || player->MyGuild->Gold < repairCost)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        player->MyGuild->Gold -= repairCost;
                        S::GuildStorageGoldChange *tempVar14 = new S::GuildStorageGoldChange();
                        tempVar14->Type = 2;
                        tempVar14->Amount = repairCost;
                        player->MyGuild->SendServerPacket(tempVar14);

                        conquestWall->Repair();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar14' statement was not added since tempVar14 was passed to a method or constructor. Handle memory management manually.
                }
                    break;
                case ActionType::ConquestSiege:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (!int::TryParse(param[1], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        ConquestSiegeObject *conquestSiege = conquest->SiegeList.FirstOrDefault([&] (std::any z)
                        {
                            return z->Index == tempInt;
                        });
                        if (conquestSiege == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (conquestSiege->Gate != nullptr)
                        {
                            if (!conquestSiege->Gate->Dead)
                            {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                                return;
                            }
                        }

                        if (player->MyGuild == nullptr || player->MyGuild->Gold < conquestSiege->GetRepairCost())
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        player->MyGuild->Gold -= static_cast<unsigned int>(conquestSiege->GetRepairCost());
                        S::GuildStorageGoldChange *tempVar15 = new S::GuildStorageGoldChange();
                        tempVar15->Type = 2;
                        tempVar15->Amount = static_cast<unsigned int>(conquestSiege->GetRepairCost());
                        player->MyGuild->SendServerPacket(tempVar15);

                        conquestSiege->Repair();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar15' statement was not added since tempVar15 was passed to a method or constructor. Handle memory management manually.
                }
                    break;
                case ActionType::TakeConquestGold:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (player->MyGuild != nullptr && player->MyGuild->Guildindex == conquest->Owner)
                        {
                            player->MyGuild->Gold += conquest->GoldStorage;
                            S::GuildStorageGoldChange *tempVar16 = new S::GuildStorageGoldChange();
                            tempVar16->Type = 3;
                            tempVar16->Amount = conquest->GoldStorage;
                            player->MyGuild->SendServerPacket(tempVar16);
                            conquest->GoldStorage = 0;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar16' statement was not added since tempVar16 was passed to a method or constructor. Handle memory management manually.
                        }
                }
                    break;
                case ActionType::SetConquestRate:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        byte tempByte;
                        if (!unsigned char::TryParse(param[1], tempByte))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        if (player->MyGuild != nullptr && player->MyGuild->Guildindex == conquest->Owner)
                        {
                            conquest->npcRate = tempByte;
                        }
                }
                    break;
                case ActionType::StartConquest:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        ConquestGame tempGame;

                        if (!ConquestGame::TryParse(param[1], tempGame))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (!conquest->WarIsOn)
                        {
                            conquest->StartType = ConquestType::Forced;
                            conquest->GameType = tempGame;
                            conquest->StartWar(tempGame);
                        }
                }
                    break;
                case ActionType::ScheduleConquest:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (player->MyGuild != nullptr && player->MyGuild->Guildindex != conquest->Owner && !conquest->WarIsOn)
                        {
                            conquest->AttackerID = player->MyGuild->Guildindex;
                        }
                }
                    break;
                case ActionType::OpenGate:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto Conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (Conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (!int::TryParse(param[1], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        ConquestGateObject *OpenGate = Conquest->GateList.FirstOrDefault([&] (std::any z)
                        {
                            return z->Index == tempInt;
                        });
                        if (OpenGate == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        if (OpenGate->Gate == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        OpenGate->Gate->OpenDoor();
                }
                    break;
                case ActionType::CloseGate:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        auto conquest = getEnvir()->Conquests.FirstOrDefault([&] (std::any z)
                        {
                            return z::Info->Index == tempInt;
                        });
                        if (conquest == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        if (!int::TryParse(param[1], tempInt))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        ConquestGateObject *CloseGate = conquest->GateList.FirstOrDefault([&] (std::any z)
                        {
                            return z->Index == tempInt;
                        });
                        if (CloseGate == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        if (CloseGate->Gate == nullptr)
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        CloseGate->Gate->CloseDoor();
                }
                    break;
                case ActionType::OpenBrowser:
                {
                        S::OpenBrowser *tempVar17 = new S::OpenBrowser();
                        tempVar17->Url = param[0];
                        player->Enqueue(tempVar17);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar17' statement was not added since tempVar17 was passed to a method or constructor. Handle memory management manually.
                }
                    break;
                case ActionType::GetRandomText:
                {
                        std::string randomTextPath = FileSystem::combine(Settings::NPCPath, param[0]);
                        if (!FileSystem::fileExists(randomTextPath))
                        {
                            getMessageQueue()->Enqueue(StringHelper::formatSimple("the randomTextFile:{0} does not exist.", randomTextPath));
                        }
                        else
                        {
                            auto lines = File::ReadAllLines(randomTextPath);
                            int index = getEnvir()->Random->Next(0, lines.size());
                            std::string randomText = lines[index];
                            AddVariable(player, param[1], randomText);
                        }
                }
                    break;
                case ActionType::PlaySound:
                {
                        int soundID;
                        if (!int::TryParse(param[0], soundID))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }
                        S::PlaySound *tempVar18 = new S::PlaySound();
                        tempVar18->Sound = soundID;
                        player->Enqueue(tempVar18);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar18' statement was not added since tempVar18 was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                case ActionType::SetTimer:
                {
                        int seconds;
                        byte type;
                        if (!int::TryParse(param[1], seconds) || !unsigned char::TryParse(param[2], type))
                        {
//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
                            return;
                        }

                        player->SetTimer(param[0], seconds, type);
                }
                    break;
                case ActionType::ExpireTimer:
                {
                        player->ExpireTimer(param[0]);
                }
                    break;
                case ActionType::UnequipItem:
                {
                        auto slot = param[0];

                        for (int e = 0; e < player->Info->Equipment.size(); e++)
                        {
                            auto item = player->Info->Equipment[e];

                            if (item == nullptr)
                            {
                                continue;
                            }

                            auto slotName = static_cast<EquipmentSlot>(e);

//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                            if (!slot.empty() && StringHelper::toLower(slot) != slotName.ToString().ToLower())
                            {
                                continue;
                            }

                            if (!player->CanRemoveItem(MirGridType::Inventory, item) || item->Cursed || item->WeddingRing != -1)
                            {
                                continue;
                            }

                            for (int k = 0; k < player->Info->Inventory.size(); k++)
                            {
                                auto freeSlot = player->Info->Inventory[k];

                                if (freeSlot != nullptr)
                                {
                                    continue;
                                }

                                player->Info->Equipment[e] = nullptr;
                                player->Info->Inventory[k] = item;

                                player->Report->ItemMoved(item, MirGridType::Equipment, MirGridType::Inventory, e, k);

                                break;
                            }
                        }

                        S::UserSlotsRefresh *packet = new S::UserSlotsRefresh();
                        packet->Inventory = std::vector<UserItem*>(player->Info->Inventory.size());
                        packet->Equipment = std::vector<UserItem*>(player->Info->Equipment.size());

                        player->Info->Inventory.CopyTo(packet->Inventory, 0);
                        player->Info->Equipment.CopyTo(packet->Equipment, 0);

                        player->Enqueue(packet);

                        player->RefreshStats();

//C# TO C++ CONVERTER TODO TASK: A 'delete packet' statement was not added since packet was passed to a method or constructor. Handle memory management manually.
                }
                    break;
            }
        }

//C# TO C++ CONVERTER TODO TASK: A 'delete mailInfo' statement was not added since mailInfo was passed to a method or constructor. Handle memory management manually.
    }

    void NPCSegment::Act(std::vector<NPCActions*> &acts, MonsterObject *monster)
    {
        for (auto i = 0; i < acts.size(); i++)
        {
            NPCActions *act = acts[i];
            std::vector<std::string> param = act->Params.Select([&] (std::any t)
            {
                return FindVariable(monster, t);
            }).ToList();

            for (int j = 0; j < param.size(); j++)
            {
                auto parts = param[j].Split(std::vector<char> {' '}, StringSplitOptions::RemoveEmptyEntries);

                if (parts.empty())
                {
                    continue;
                }

                for (auto part : parts)
                {
                    param[j] = StringHelper::replace(param[j], part, ReplaceValue(monster, part));
                }
            }

            switch (act->Type)
            {
                case ActionType::GiveHP:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }
                        monster->ChangeHP(tempInt);
                }
                    break;
                case ActionType::GlobalMessage:
                {
                        ChatType chatType;
                        if (!Enum::TryParse(param[1], true, chatType))
                        {
                            return;
                        }

                        auto p = new S::Chat();
                        p->Message = param[0];
                        p->Type = chatType;
                        getEnvir()->Broadcast(p);

//C# TO C++ CONVERTER TODO TASK: A 'delete p' statement was not added since p was passed to a method or constructor. Handle memory management manually.
                }
                    break;

                /* //mobs have no real "delayed" npc code so not added this yet
                                    case ActionType.Goto:
                                        DelayedAction action = new DelayedAction(DelayedType.NPC, -1, player.NPCID, "[" + param[0] + "]");
                                        player.ActionList.Add(action);
                                        break;
                */
                case ActionType::Break:
                {
                        Page->BreakFromSegments = true;
                }
                    break;

                case ActionType::Param1:
                {
                        int tempInt;
                        if (!int::TryParse(param[1], tempInt))
                        {
                            return;
                        }

                        Param1 = param[0];
                        Param1Instance = tempInt;
                }
                    break;

                case ActionType::Param2:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }

                        Param2 = tempInt;
                }
                    break;

                case ActionType::Param3:
                {
                        int tempInt;
                        if (!int::TryParse(param[0], tempInt))
                        {
                            return;
                        }

                        Param3 = tempInt;
                }
                    break;

                case ActionType::Mongen:
                {
                        if (Param1 == "" || Param2 == 0 || Param3 == 0)
                        {
                            return;
                        }
                        byte tempByte;
                        if (!unsigned char::TryParse(param[1], tempByte))
                        {
                            return;
                        }

                        auto map = getEnvir()->GetMapByNameAndInstance(Param1, Param1Instance);
                        if (map == nullptr)
                        {
                            return;
                        }

                        auto monInfo = getEnvir()->GetMonsterInfo(param[0]);
                        if (monInfo == nullptr)
                        {
                            return;
                        }

                        for (int j = 0; j < tempByte; j++)
                        {
                            MonsterObject *mob = MonsterObject::GetMonster(monInfo);
                            if (mob == nullptr)
                            {
                                return;
                            }
                            mob->setDirection((MirDirection)0);
                            mob->ActionTime = getEnvir()->getTime() + 1000;
                            Point tempVar(Param2, Param3);
                            mob->Spawn(map, &tempVar);
                        }
                }
                    break;
                case ActionType::MonClear:
                {
                        int tempInt;
                        if (!int::TryParse(param[1], tempInt))
                        {
                            return;
                        }

                        auto map = getEnvir()->GetMapByNameAndInstance(param[0], tempInt);
                        if (map == nullptr)
                        {
                            return;
                        }

                        for (auto cell : *map->Cells)
                        {
                            if (cell.empty() || cell.Objects == nullptr)
                            {
                                continue;
                            }

                            for (int j = 0; j < cell.Objects->Count(); j++)
                            {
                                MapObject *ob = cell.Objects[j];

                                if (ob->getRace() != ObjectType::Monster)
                                {
                                    continue;
                                }
                                if (ob->Dead)
                                {
                                    continue;
                                }
                                ob->Die();
                            }
                        }
                }
                    break;

                case ActionType::Mov:
                {
                        std::string value = param[0];
                        AddVariable(monster, value, param[1]);
                }
                    break;

                case ActionType::Calc:
                {
                        int left;
                        int right;

                        bool resultLeft = int::TryParse(param[0], left);
                        bool resultRight = int::TryParse(param[2], right);

                        if (resultLeft && resultRight)
                        {
                            try
                            {
                                int result = Calculate(param[1], left, right);
                                AddVariable(monster, StringHelper::replace(param[3], "-", ""), std::to_string(result));
                            }
                            catch (const std::invalid_argument &e1)
                            {
                                getMessageQueue()->Enqueue(StringHelper::formatSimple("Incorrect operator: {0}, Page: {1}", param[1], Key));
                            }
                        }
                        else
                        {
                            AddVariable(monster, StringHelper::replace(param[3], "-", ""), param[0] + param[2]);
                        }
                }
                    break;

                case ActionType::GiveBuff:
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
                        if (!Enum::IsDefined(typeof(BuffType), param[0]))
                        {
                            return;
                        }

                        int tempInt;
                        int::TryParse(param[1], tempInt);
                        bool infinite;
                        bool::TryParse(param[2], infinite);
                        bool visible;
                        bool::TryParse(param[3], visible);
                        bool stackable;
                        bool::TryParse(param[4], stackable);

//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
                        Stats tempVar2();
                        monster->AddBuff(static_cast<BuffType>(std::any_cast<unsigned char>(Enum::Parse(typeof(BuffType), param[0], true))), monster, Settings::Second * tempInt, &tempVar2, visible, infinite, stackable);
                }
                    break;

                case ActionType::RemoveBuff:
                {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
                        if (!Enum::IsDefined(typeof(BuffType), param[0]))
                        {
                            return;
                        }

//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
                        BuffType bType = static_cast<BuffType>(std::any_cast<unsigned char>(Enum::Parse(typeof(BuffType), param[0])));

                        monster->RemoveBuff(bType);
                }
                    break;

                case ActionType::LoadValue:
                {
                        std::string val = param[0];
                        std::string filePath = param[1];
                        std::string header = param[2];
                        std::string key = param[3];

                        auto reader = new InIReader(filePath);
                        std::string loadedString = reader->ReadString(header, key, "");

                        if (loadedString == "")
                        {
                            delete reader;
                            break;
                        }
                        AddVariable(monster, val, loadedString);

                        delete reader;
                }
                    break;

                case ActionType::SaveValue:
                {
                        std::string filePath = param[0];
                        std::string header = param[1];
                        std::string key = param[2];
                        std::string val = param[3];

                        auto reader = new InIReader(filePath);
                        reader->Write(header, key, val);

                        delete reader;
                }
                    break;
            }
        }
    }

    void NPCSegment::Success(PlayerObject *player)
    {
        Act(ActList, player);

        auto parseSay = std::vector<std::string>(Say);
        parseSay = ParseSay(player, parseSay);

        player->NPCSpeech.insert(player->NPCSpeech.end(), parseSay.begin(), parseSay.end());
    }

    void NPCSegment::Failed(PlayerObject *player)
    {
        Act(ElseActList, player);

        auto parseElseSay = std::vector<std::string>(ElseSay);
        parseElseSay = ParseSay(player, parseElseSay);

        player->NPCSpeech.insert(player->NPCSpeech.end(), parseElseSay.begin(), parseElseSay.end());
    }

    void NPCSegment::Success(MonsterObject *Monster)
    {
        Act(ActList, Monster);
    }

    void NPCSegment::Failed(MonsterObject *Monster)
    {
        Act(ElseActList, Monster);
    }

    void NPCSegment::Success()
    {
        Act(ActList);
    }

    void NPCSegment::Failed()
    {
        Act(ElseActList);
    }

    int NPCSegment::Calculate(const std::string &op, int left, int right)
    {
//C# TO C++ CONVERTER NOTE: The following 'switch' operated on a string and was converted to C++ 'if-else' logic:
//        switch (op)
//ORIGINAL LINE: case "+":
        if (op == "+")
        {
                return left + right;
        }
//ORIGINAL LINE: case "-":
        else if (op == "-")
        {
                return left - right;
        }
//ORIGINAL LINE: case "*":
        else if (op == "*")
        {
                return left * right;
        }
//ORIGINAL LINE: case "/":
        else if (op == "/")
        {
                return left / right;
        }
        else
        {
//C# TO C++ CONVERTER TODO TASK: This exception's constructor requires only one argument:
//ORIGINAL LINE: throw new ArgumentException("Invalid sum operator: {0}", op);
                throw std::invalid_argument("Invalid sum operator: {0}");
        }
    }
}
